166 lines
5.3 KiB
C#
166 lines
5.3 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
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 AppAuthController : IDisposable
|
|
{
|
|
#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 void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo permessi2funzione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Permessi2FunzioneModel> Permessi2FunzioneGetAll()
|
|
{
|
|
List<Permessi2FunzioneModel> dbResult = new List<Permessi2FunzioneModel>();
|
|
using (AppAuthContext dbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetPermessi2Funzione
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco permessi2funzione filtrato x elenco funzioni
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Permessi2FunzioneModel> Permessi2FunzioneGetFilt(List<string> FunList)
|
|
{
|
|
List<Permessi2FunzioneModel> dbResult = new List<Permessi2FunzioneModel>();
|
|
using (AppAuthContext dbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetPermessi2Funzione
|
|
.Where(x => FunList.Contains(x.CodFunzione))
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco completo permessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PermessiModel> PermessiGetAll()
|
|
{
|
|
List<PermessiModel> dbResult = new List<PermessiModel>();
|
|
using (AppAuthContext dbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetPermessi
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco permessi dato elenco funzioni
|
|
/// </summary>
|
|
/// <param name="ListCodFun"></param>
|
|
/// <returns></returns>
|
|
public List<PermessiModel> PermessiGetByFunc(List<string> ListCodFun)
|
|
{
|
|
List<PermessiModel> dbResult = new List<PermessiModel>();
|
|
using (AppAuthContext dbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
var listPer = PermessiGetAll();
|
|
var listP2F_all = Permessi2FunzioneGetAll();
|
|
//var listP2F = Permessi2FunzioneGetFilt(ListCodFun);
|
|
var listP2F= listP2F_all
|
|
.Where(x => ListCodFun.Contains(x.CodFunzione))
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
var query = from permesso in listPer
|
|
join p2f in listP2F on permesso.CodPermesso equals p2f.CodPermesso
|
|
select permesso;
|
|
|
|
dbResult = query.Distinct().ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
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<VocabolarioModel> VocabolarioGetAll()
|
|
{
|
|
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
|
using (AppAuthContext localDbCtx = new AppAuthContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetVocabolario
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration { get; set; } = null!;
|
|
private static AppAuthContext dbCtx { get; set; } = null!;
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
}
|