From 167c9d89d402e473c651faa826838dc93b51195e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 4 Jul 2022 18:48:03 +0200 Subject: [PATCH] Aggiunto modelli accesso dati x filtro QRCode utenti --- MP.AppAuth/AppAuthContext.cs | 33 +++++++++++ MP.AppAuth/Controllers/AppAuthController.cs | 65 +++++++++++++++++++++ MP.AppAuth/Controllers/MPController .cs | 27 ++++----- MP.AppAuth/Models/AnagraficaGruppi.cs | 15 +++++ MP.AppAuth/Models/Gruppi2Operatori.cs | 13 +++++ MP.AppAuth/MoonProContext.cs | 4 +- 6 files changed, 143 insertions(+), 14 deletions(-) create mode 100644 MP.AppAuth/Models/AnagraficaGruppi.cs create mode 100644 MP.AppAuth/Models/Gruppi2Operatori.cs diff --git a/MP.AppAuth/AppAuthContext.cs b/MP.AppAuth/AppAuthContext.cs index 306cc5c2..16c3cabe 100644 --- a/MP.AppAuth/AppAuthContext.cs +++ b/MP.AppAuth/AppAuthContext.cs @@ -54,7 +54,9 @@ namespace MP.AppAuth #region Public Properties + public virtual DbSet DbSetAnagraficaGruppi { get; set; } public virtual DbSet DbSetAnagOpr { get; set; } + public virtual DbSet DbSetGruppi2Oper { get; set; } public virtual DbSet DbSetUpdMan { get; set; } public virtual DbSet DbSetVocabolario { get; set; } @@ -103,6 +105,37 @@ namespace MP.AppAuth .HasMaxLength(500); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.CodGruppo); + + entity.ToTable("AnagraficaGruppi"); + + entity.Property(e => e.CodGruppo).HasMaxLength(50); + + entity.Property(e => e.DescrGruppo) + .IsRequired() + .HasMaxLength(250) + .HasDefaultValueSql("('')"); + + entity.Property(e => e.SelEnabled).HasComment("Indica se sia selezionabile a livello di tendina x inserimento BCode"); + + entity.Property(e => e.TipoGruppo) + .IsRequired() + .HasMaxLength(50) + .HasDefaultValueSql("('REPARTO')") + .HasComment("tipo gruppo: reparto (es x gestione operatori assegnati), GRUPPO FASE (es macchien che fanno lo stesso tipo di lavoro), ..."); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.MatrOpr, e.CodGruppo }); + + entity.ToTable("Gruppi2Operatori"); + + entity.Property(e => e.CodGruppo).HasMaxLength(50); + }); + // modelBuilder.Seed(); diff --git a/MP.AppAuth/Controllers/AppAuthController.cs b/MP.AppAuth/Controllers/AppAuthController.cs index e441149a..28e2c0c3 100644 --- a/MP.AppAuth/Controllers/AppAuthController.cs +++ b/MP.AppAuth/Controllers/AppAuthController.cs @@ -31,6 +31,38 @@ namespace MP.AppAuth.Controllers #region Public Methods + /// + /// Elenco Record x Gruppi + /// + /// + public List AnagGruppiFilt(string codTipo) + { + List dbResult = new List(); + using (AppAuthContext localDbCtx = new AppAuthContext(_configuration)) + { + dbResult = localDbCtx + .DbSetAnagraficaGruppi + .Where(x => x.TipoGruppo == codTipo || x.SelEnabled) + .ToList(); + } + return dbResult; + } + /// + /// Elenco Record x Gruppi + /// + /// + public List AnagGruppiGetAll() + { + List dbResult = new List(); + using (AppAuthContext localDbCtx = new AppAuthContext(_configuration)) + { + dbResult = localDbCtx + .DbSetAnagraficaGruppi + .ToList(); + } + return dbResult; + } + public List AnagOpGetAll(string searchVal) { List dbResult = new List(); @@ -53,6 +85,39 @@ namespace MP.AppAuth.Controllers // ritorno return dbResult; } + public List AnagOpByGruppoGetAll(string codGruppo, string searchVal) + { + List dbResult = new List(); + using (AppAuthContext localDbCtx = new AppAuthContext(_configuration)) + { + if (!string.IsNullOrEmpty(searchVal)) + { + dbResult = localDbCtx + .DbSetGruppi2Oper + .Where(x => x.CodGruppo == codGruppo) + .Join( + localDbCtx.DbSetAnagOpr.Where(x => x.Cognome.Contains(searchVal) || x.Nome.Contains(searchVal)), + gruppo => gruppo.MatrOpr, + operatore => operatore.MatrOpr, + (gruppo, operatore) => operatore + ).ToList(); + } + else + { + dbResult = localDbCtx + .DbSetGruppi2Oper + .Where(x => x.CodGruppo == codGruppo) + .Join( + localDbCtx.DbSetAnagOpr, + gruppo => gruppo.MatrOpr, + operatore => operatore.MatrOpr, + (gruppo, operatore) => operatore + ).ToList(); + } + } + // ritorno + return dbResult; + } public void Dispose() { diff --git a/MP.AppAuth/Controllers/MPController .cs b/MP.AppAuth/Controllers/MPController .cs index 794b7d64..77cd4940 100644 --- a/MP.AppAuth/Controllers/MPController .cs +++ b/MP.AppAuth/Controllers/MPController .cs @@ -2,22 +2,17 @@ using NLog; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MP.AppAuth.Controllers { public class MPController : IDisposable { - #region Private Fields + #region Public Fields - private static IConfiguration _configuration; - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); public static AppAuth.Controllers.MPController dbController; - #endregion Private Fields + #endregion Public Fields #region Public Constructors @@ -31,12 +26,6 @@ namespace MP.AppAuth.Controllers #region Public Methods - public void Dispose() - { - // Clear database controller - dbController.Dispose(); - } - /// /// Elenco Record x AnagKeyValue @@ -54,7 +43,19 @@ namespace MP.AppAuth.Controllers return dbResult; } + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + } #endregion Public Methods + + #region Private Fields + + private static IConfiguration _configuration; + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields } } \ No newline at end of file diff --git a/MP.AppAuth/Models/AnagraficaGruppi.cs b/MP.AppAuth/Models/AnagraficaGruppi.cs new file mode 100644 index 00000000..ce30e084 --- /dev/null +++ b/MP.AppAuth/Models/AnagraficaGruppi.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace MP.AppAuth.Models +{ + public partial class AnagraficaGruppi + { + public string CodGruppo { get; set; } + public string TipoGruppo { get; set; } + public string DescrGruppo { get; set; } + public bool SelEnabled { get; set; } + } +} diff --git a/MP.AppAuth/Models/Gruppi2Operatori.cs b/MP.AppAuth/Models/Gruppi2Operatori.cs new file mode 100644 index 00000000..207ca2c1 --- /dev/null +++ b/MP.AppAuth/Models/Gruppi2Operatori.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace MP.AppAuth.Models +{ + public partial class Gruppi2Operatori + { + public int MatrOpr { get; set; } + public string CodGruppo { get; set; } + } +} diff --git a/MP.AppAuth/MoonProContext.cs b/MP.AppAuth/MoonProContext.cs index 09f1d31c..d8bb56a6 100644 --- a/MP.AppAuth/MoonProContext.cs +++ b/MP.AppAuth/MoonProContext.cs @@ -71,7 +71,7 @@ namespace MP.AppAuth public virtual DbSet ListValues { get; set; } public virtual DbSet Macchines { get; set; } public virtual DbSet UpdMan { get; set; } - public virtual DbSet Vocabolario { get; set; } + public virtual DbSet DbSetVocabolario { get; set; } #endregion Public Properties @@ -503,6 +503,8 @@ namespace MP.AppAuth .HasMaxLength(500); }); + + OnModelCreatingPartial(modelBuilder); }