126 lines
3.8 KiB
C#
126 lines
3.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.AppAuth.Controllers
|
|
{
|
|
public class AppAuthController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static AppAuthContext dbCtx;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public AppAuthController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
dbCtx = new AppAuthContext(configuration);
|
|
Log.Info("Avviata classe AppAuthController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public List<Models.AnagraficaOperatori> AnagOpGetAll(string searchVal)
|
|
{
|
|
List<Models.AnagraficaOperatori> dbResult = new List<Models.AnagraficaOperatori>();
|
|
using (AppAuthContext localDbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagOpr
|
|
.Where(x => x.Cognome.Contains(searchVal) || x.Nome.Contains(searchVal))
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagOpr
|
|
.ToList();
|
|
}
|
|
}
|
|
// ritorno
|
|
return dbResult;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
public void ResetController()
|
|
{
|
|
dbCtx = new AppAuthContext(_configuration);
|
|
Log.Info("Effettuato reset AppAuthController");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annulla modifiche su una specifica entity (cancel update)
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public bool RollBackEntity(object item)
|
|
{
|
|
bool answ = false;
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x gestione Update
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Models.UpdMan> UpdManGetAll()
|
|
{
|
|
List<Models.UpdMan> dbResult = new List<Models.UpdMan>();
|
|
using (AppAuthContext localDbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetUpdMan
|
|
.OrderBy(x => x.Ordinal)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x gestione Update
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Models.Vocabolario> VocabolarioGetAll()
|
|
{
|
|
List<Models.Vocabolario> dbResult = new List<Models.Vocabolario>();
|
|
using (AppAuthContext localDbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetVocabolario
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |