Completata review metodo update licenza
This commit is contained in:
@@ -342,11 +342,35 @@ namespace LiMan.DB.Controllers
|
||||
{
|
||||
if (licenza.IsValid && (licenza.NumLicenze >= (attivList.Count + ParamDict.Count)))
|
||||
{
|
||||
DateTime vetoDate = DateTime.Today.AddDays(numDayVeto);
|
||||
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
||||
DateTime oggi = DateTime.Today;
|
||||
DateTime vetoDate = oggi.AddDays(numDayVeto);
|
||||
using (LMDbContext dbCtx = new LMDbContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
// cerco eventuali licenze preesistenti (per CodImp) e le elimino SE sono libere...
|
||||
List<SubLicenzaModel> list2rem = new List<SubLicenzaModel>();
|
||||
foreach (var item in ParamDict)
|
||||
{
|
||||
var rec2del = dbCtx
|
||||
.DbSetSubLicenze
|
||||
.Where(x => x.CodImpiego == item.Key && x.VetoUnlock <= oggi)
|
||||
.FirstOrDefault();
|
||||
if(rec2del!=null)
|
||||
{
|
||||
list2rem.Add(rec2del);
|
||||
}
|
||||
}
|
||||
// se ce ne sono rimuovo e salvo...
|
||||
if(list2rem!=null && list2rem.Count>0)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetSubLicenze
|
||||
.RemoveRange(list2rem);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
// genero subLicenze...
|
||||
var newRec = ParamDict
|
||||
.Select(x => new SubLicenzaModel()
|
||||
@@ -358,11 +382,11 @@ namespace LiMan.DB.Controllers
|
||||
Chiave = x.Value
|
||||
})
|
||||
.ToList();
|
||||
localDbCtx
|
||||
dbCtx
|
||||
.DbSetSubLicenze
|
||||
.AddRange(newRec);
|
||||
|
||||
localDbCtx.SaveChanges();
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user