86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
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<DipendentiModel> DipendentiGetAll()
|
|
{
|
|
List<DipendentiModel> dbResult = new List<DipendentiModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetDipendenti
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Annulla modifiche su una specifica entity (cancel update)
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|