AuthUtente x LAND:

- aggiunta DbModels
- aggiunta controillers
- aggiunta servizio
This commit is contained in:
Samuele Locatelli
2024-09-03 17:18:59 +02:00
parent c5914dcef7
commit d621f7e6fc
7 changed files with 415 additions and 30 deletions
+68
View File
@@ -59,6 +59,8 @@ namespace MP.AppAuth
public virtual DbSet<Gruppi2Operatori> DbSetGruppi2Oper { get; set; }
public virtual DbSet<UpdMan> DbSetUpdMan { get; set; }
public virtual DbSet<VocabolarioModel> DbSetVocabolario { get; set; }
public virtual DbSet<PermessiModel> DbSetPermessi { get; set; } = null!;
public virtual DbSet<Permessi2FunzioneModel> DbSetPermessi2Funzione { get; set; } = null!;
#endregion Public Properties
@@ -134,6 +136,72 @@ namespace MP.AppAuth
entity.Property(e => e.CodGruppo).HasMaxLength(50);
});
modelBuilder.Entity<PermessiModel>(entity =>
{
entity.HasKey(e => e.CodPermesso);
entity.ToTable("Permessi");
entity.Property(e => e.CodPermesso)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("COD_PERMESSO")
.UseCollation("Latin1_General_CI_AS");
entity.Property(e => e.Descrizione)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("DESCRIZIONE")
.UseCollation("Latin1_General_CI_AS");
entity.Property(e => e.Gruppo).HasColumnName("GRUPPO");
entity.Property(e => e.Nome)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("NOME")
.UseCollation("Latin1_General_CI_AS");
entity.Property(e => e.Numero).HasColumnName("NUMERO");
entity.Property(e => e.Url)
.HasMaxLength(250)
.IsUnicode(false)
.HasColumnName("URL")
.UseCollation("Latin1_General_CI_AS");
});
modelBuilder.Entity<Permessi2FunzioneModel>(entity =>
{
entity.HasKey(e => new { e.CodPermesso, e.CodFunzione });
entity.ToTable("Permessi2Funzione");
entity.Property(e => e.CodPermesso)
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnName("COD_PERMESSO")
.UseCollation("Latin1_General_CI_AS");
entity.Property(e => e.CodFunzione)
.HasMaxLength(31)
.HasColumnName("COD_FUNZIONE")
.UseCollation("Latin1_General_CI_AS");
entity.Property(e => e.Readwrite)
.HasMaxLength(1)
.IsUnicode(false)
.HasColumnName("READWRITE")
.IsFixedLength()
.UseCollation("Latin1_General_CI_AS");
entity.HasOne(d => d.PermessiNav)
.WithMany(p => p.Permessi2FunzioneNav)
.HasForeignKey(d => d.CodPermesso)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Permessi2Funzione_Permessi");
});
//
modelBuilder.Seed();
+103 -30
View File
@@ -11,14 +11,6 @@ namespace MP.AppAuth.Controllers
{
public class AppAuthController : IDisposable
{
#region Private Fields
private static IConfiguration _configuration;
private static AppAuthContext dbCtx;
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Public Constructors
public AppAuthController(IConfiguration configuration)
@@ -48,6 +40,7 @@ namespace MP.AppAuth.Controllers
}
return dbResult;
}
/// <summary>
/// Elenco Record x Gruppi
/// </summary>
@@ -64,28 +57,6 @@ namespace MP.AppAuth.Controllers
return dbResult;
}
public List<AnagraficaOperatori> AnagOpGetAll(string searchVal)
{
List<AnagraficaOperatori> dbResult = new List<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 List<AnagraficaOperatori> AnagOpByGruppoGetFilt(string codGruppo, string searchVal)
{
List<AnagraficaOperatori> dbResult = new List<AnagraficaOperatori>();
@@ -122,12 +93,106 @@ namespace MP.AppAuth.Controllers
return dbResult;
}
public List<AnagraficaOperatori> AnagOpGetAll(string searchVal)
{
List<AnagraficaOperatori> dbResult = new List<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();
}
/// <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 = Permessi2FunzioneGetFilt(ListCodFun);
var query = from permesso in listPer
join p2f in listP2F on permesso.CodPermesso equals p2f.CodPermesso
select permesso;
dbResult = query.ToList();
}
return dbResult;
}
public void ResetController()
{
dbCtx = new AppAuthContext(_configuration);
@@ -190,5 +255,13 @@ namespace MP.AppAuth.Controllers
}
#endregion Public Methods
#region Private Fields
private static IConfiguration _configuration;
private static AppAuthContext dbCtx;
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
}
}
@@ -0,0 +1,59 @@
using Microsoft.Extensions.Configuration;
using MP.AppAuth.Models;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.AppAuth.Controllers
{
public class MPUserController : IDisposable
{
#region Public Constructors
public MPUserController(IConfiguration configuration)
{
_configuration = configuration;
Log.Info("Avviata classe MPUserController");
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Elenco Diritti utente da modulo
/// </summary>
/// <param name="UserName">UserName cercato</param>
/// <param name="Modulo">Modulo desiderato, se "" allora tutti i diritti</param>
/// <returns></returns>
public List<UserDirittiModel> DirittiUtente(string UserName, string Modulo)
{
List<UserDirittiModel> dbResult = new List<UserDirittiModel>();
using (UserAuthContext dbCtx = new UserAuthContext(_configuration))
{
dbResult = dbCtx
.DbSetUserDiritti
.Where(x => x.UserName == UserName && (string.IsNullOrEmpty(Modulo) || x.Modulo == Modulo))
.ToList();
}
return dbResult;
}
public void Dispose()
{
GC.Collect();
}
#endregion Public Methods
#region Private Fields
private static IConfiguration _configuration = null!;
private static Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.AppAuth.Models
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
[Table("Permessi2Funzione")]
public partial class Permessi2FunzioneModel
{
public string CodPermesso { get; set; } = null!;
public string CodFunzione { get; set; } = null!;
public string? Readwrite { get; set; }
public virtual PermessiModel PermessiNav { get; set; } = null!;
}
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.AppAuth.Models
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
[Table("Permessi")]
public partial class PermessiModel
{
public PermessiModel()
{
Permessi2FunzioneNav = new HashSet<Permessi2FunzioneModel>();
}
public string CodPermesso { get; set; } = null!;
public string Url { get; set; } = null!;
public int? Gruppo { get; set; }
public int? Numero { get; set; }
public string? Nome { get; set; }
public string? Descrizione { get; set; }
public virtual ICollection<Permessi2FunzioneModel> Permessi2FunzioneNav { get; set; }
}
}
+29
View File
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.AppAuth.Models
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
[Table("DIRITTI")]
public partial class UserDirittiModel
{
[Column("USER_NAME"), MaxLength(50)]
public string UserName { get; set; } = "";
[Column("COD_CDC"), MaxLength(50)]
public string CdC { get; set; } = "";
[Column("COD_MODULO"), MaxLength(31)]
public string Modulo { get; set; } = "";
[Column("COD_FUNZIONE"), MaxLength(31)]
public string Funzione { get; set; } = "";
[Column("VALUE"), MaxLength(255)]
public string? Valore { get; set; } = "";
}
}
+104
View File
@@ -0,0 +1,104 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using MP.AppAuth.Models;
using NLog;
using NLog.Fluent;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MP.AppAuth
{
public partial class UserAuthContext : DbContext
{
#region Public Constructors
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
public UserAuthContext()
{
}
public UserAuthContext(IConfiguration configuration)
{
_configuration = configuration;
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
{
Log.Error(exc, "Exception during context initialization 01");
}
}
public UserAuthContext(DbContextOptions<AppAuthContext> options) : base(options)
{
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
{
Log.Error(exc, "Exception during context initialization 02");
}
}
#endregion Public Constructors
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
string connString = _configuration.GetConnectionString("MP.Land.Auth");
if (!string.IsNullOrEmpty(connString))
{
optionsBuilder.UseSqlServer(connString);
}
else
{
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro_Anagrafica;Trusted_Connection=True;");
}
}
}
#region Public Properties
public virtual DbSet<UserDirittiModel> DbSetUserDiritti { get; set; } = null!;
#endregion Public Properties
#region Protected Methods
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserDirittiModel>(entity =>
{
entity.HasKey(e => new { e.UserName, e.CdC, e.Modulo, e.Funzione });
entity.ToTable("DIRITTI");
});
OnModelCreatingPartial(modelBuilder);
}
#endregion Protected Methods
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private IConfiguration _configuration;
#endregion Private Fields
#region Private Methods
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
#endregion Private Methods
}
}