87 lines
2.4 KiB
C#
87 lines
2.4 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 List<RemnantsModel> RemnantsGetAll()
|
|
{
|
|
List<RemnantsModel> dbResult = new List<RemnantsModel>();
|
|
using (NKCContext localDbCtx = new NKCContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetRemnants
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<RemnantsModel> RemnantsGetFilt(int matId, int minQty)
|
|
{
|
|
List<RemnantsModel> dbResult = new List<RemnantsModel>();
|
|
using (NKCContext localDbCtx = new NKCContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetRemnants
|
|
.Where(x => (x.MatID == matId || matId == 0) && (x.QtyAvail >= minQty || minQty == 0))
|
|
.OrderBy(o => o.Area)
|
|
.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;
|
|
}
|
|
|
|
}
|
|
}
|