using GPW.CORE.Data.DbModels; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using NLog; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GPW.CORE.Data.Controllers { public class GPWController : IDisposable { private static IConfiguration _configuration = null!; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); public GPWController(IConfiguration configuration) { _configuration = configuration; } public bool DbForceMigrate() { bool answ = false; using (GPWContext localDbCtx = new GPWContext(_configuration)) { try { localDbCtx.DbForceMigrate(); answ = true; } catch (Exception exc) { Log.Error($"Eccezione in DbForceMigrate{Environment.NewLine}{exc}"); } } return answ; } public void Dispose() { Log.Info("Dispose di GPWController"); } public List DipendentiGetAll() { List dbResult = new List(); using (GPWContext localDbCtx = new GPWContext(_configuration)) { dbResult = localDbCtx .DbSetDipendenti .ToList(); } return dbResult; } /// /// Annulla modifiche su una specifica entity (cancel update) /// /// /// public bool rollBackEntity(object item) { bool answ = false; using (GPWContext localDbCtx = new GPWContext(_configuration)) { try { if (localDbCtx.Entry(item).State == EntityState.Deleted || localDbCtx.Entry(item).State == EntityState.Modified) { localDbCtx.Entry(item).Reload(); } } catch (Exception exc) { Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}"); } } return answ; } } }