Files
NKC/REMAN/NKC.Data/Controllers/NKCController.cs
T
2021-11-18 18:24:09 +01:00

60 lines
1.5 KiB
C#

using Microsoft.Extensions.Configuration;
using NKC.Data.DbModels;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NKC.Data.Controllers
{
public class NKCController : IDisposable
{
private static IConfiguration _configuration;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
public NKCController(IConfiguration configuration)
{
_configuration = configuration;
}
public void Dispose()
{
Log.Info("Dispose di NKCController");
}
public List<MaterialModel> MaterialsGetAll()
{
List<MaterialModel> dbResult = new List<MaterialModel>();
using (NKCContext localDbCtx = new NKCContext(_configuration))
{
dbResult = localDbCtx
.DbSetMaterials
.Where(x => x.MatID > 0)
.ToList();
}
return dbResult;
}
public bool DbForceMigrate()
{
bool answ = false;
using (NKCContext localDbCtx = new NKCContext(_configuration))
{
try
{
localDbCtx.DbForceMigrate();
answ = true;
}
catch (Exception exc)
{
Log.Error($"Eccezione in DbForceMigrate");
}
}
return answ;
}
}
}