Migrazione gestione risorse in obj separati (Repository/Service)
This commit is contained in:
@@ -2674,105 +2674,6 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
return dbRestults;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione record
|
||||
/// </summary>
|
||||
/// <param name="rec2del"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> ResourcesDeleteAsync(ResourceModel rec2del)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
var currRec = dbCtx
|
||||
.DbSetResource
|
||||
.Where(x => rec2del.ResourceID > 0 && x.ResourceID == rec2del.ResourceID)
|
||||
.FirstOrDefault();
|
||||
// se trovato --> elimino
|
||||
if (currRec != null)
|
||||
{
|
||||
dbCtx.DbSetResource.Remove(rec2del);
|
||||
}
|
||||
// salvo...
|
||||
int numAct = await dbCtx.SaveChangesAsync();
|
||||
answ = numAct > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante ResourcesDeleteAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco record risorse da DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal async Task<List<ResourceModel>> ResourcesGetAllAsync()
|
||||
{
|
||||
List<ResourceModel> dbResult = new List<ResourceModel>();
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = await dbCtx
|
||||
.DbSetResource
|
||||
.Include(d => d.DriverNav)
|
||||
.Include(j => j.JobStepNav)
|
||||
.ToListAsync();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante ResourcesGetAllAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add record
|
||||
/// </summary>
|
||||
/// <param name="upsRec"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<bool> ResourcesUpsertAsync(ResourceModel upsRec)
|
||||
{
|
||||
bool answ = false;
|
||||
//using (DataLayerContext dbCtx = new DataLayerContext(_config))
|
||||
using (DataLayerContext dbCtx = new DataLayerContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
var currRec = dbCtx
|
||||
.DbSetResource
|
||||
.Where(x => upsRec.ResourceID > 0 && x.ResourceID == upsRec.ResourceID)
|
||||
.FirstOrDefault();
|
||||
// se trovato --> aggiorno
|
||||
if (currRec != null)
|
||||
{
|
||||
dbCtx.Entry(currRec).CurrentValues.SetValues(upsRec);
|
||||
}
|
||||
// se mancasse --> aggiungo
|
||||
else
|
||||
{
|
||||
dbCtx.DbSetResource.Add(upsRec);
|
||||
}
|
||||
// salvo...
|
||||
int numAct = await dbCtx.SaveChangesAsync();
|
||||
answ = numAct > 0;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante ResourcesUpsertAsync{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue merge dei dati nella tab profili del DB con le info accessorie...
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user