110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.Data.DbModels;
|
|
using MP.Core.Objects;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using static MP.Core.Objects.Enums;
|
|
|
|
namespace MP.Data.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Controller specifico x LAND FixMe ToDo !!! è ancora necessario con obj task estratti?!?!?
|
|
/// </summary>
|
|
public class MpLandController : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MpLandController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
Log.Info("Avviato MpLandController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella Config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ConfigModel> ConfigGetAll()
|
|
{
|
|
List<ConfigModel> dbResult = new List<ConfigModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetConfig
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Chiave)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_configuration = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco operatori
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagOperatoriModel> ElencoOperatori()
|
|
{
|
|
List<AnagOperatoriModel> dbResult = new List<AnagOperatoriModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbOperatori
|
|
.Where(s => s.MatrOpr > 0)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.MatrOpr)
|
|
.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 (var dbCtx = new MoonPro_STATSContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Deleted || dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Modified)
|
|
{
|
|
dbCtx.Entry(item).Reload();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |