From 623ecd6308657708f2ada3359f537f8521fe9192 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 23 Jul 2022 10:32:29 +0200 Subject: [PATCH] Update DB - aggiunta anagrafica aziende - filtro articoli --- MP.Data/Controllers/MpSpecController.cs | 103 +++++++++++++++++------- MP.Data/DatabaseModels/AnagGruppi.cs | 28 +++++++ MP.Data/MoonProContext.cs | 23 ++++++ 3 files changed, 126 insertions(+), 28 deletions(-) create mode 100644 MP.Data/DatabaseModels/AnagGruppi.cs diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 75829757..d4d44045 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -10,14 +10,6 @@ namespace MP.Data.Controllers { public class MpSpecController : IDisposable { - #region Private Fields - - private static IConfiguration _configuration; - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - - #endregion Private Fields - #region Public Constructors public MpSpecController(IConfiguration configuration) @@ -30,6 +22,53 @@ namespace MP.Data.Controllers #region Public Methods + /// + /// Elenco Gruppi tipo Azienda + /// + /// + public List AnagGruppiAziende() + { + return AnagGruppiGetTipo("AZIENDA"); + } + + /// + /// Elenco Gruppi + /// + /// + public List AnagGruppiGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetAnagGruppi + .AsNoTracking() + .OrderBy(x => x.CodGruppo) + .ToList(); + } + return dbResult; + } + + /// + /// Gruppi x tipo + /// + /// + /// + public List AnagGruppiGetTipo(string tipoGruppo) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetAnagGruppi + .Where(x => x.TipoGruppo == tipoGruppo) + .AsNoTracking() + .OrderBy(x => x.CodGruppo) + .ToList(); + } + return dbResult; + } + /// /// Elenco tabella Articoli da filtro /// @@ -59,7 +98,7 @@ namespace MP.Data.Controllers /// /// /// - public List ArticoliGetSearch(int numRecord, string azienda = "", string searchVal = "") + public List ArticoliGetSearch(int numRecord, string azienda = "*", string searchVal = "") { List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) @@ -67,7 +106,7 @@ namespace MP.Data.Controllers dbResult = dbCtx .DbSetArticoli .AsNoTracking() - .Where(x => (x.Azienda == azienda || string.IsNullOrEmpty(azienda)) && x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) + .Where(x => (x.Azienda == azienda || azienda == "*") && (x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal))) .OrderBy(x => x.CodArticolo) .Take(numRecord) .ToList(); @@ -75,6 +114,24 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco da tabella Macchine + /// + /// + public List ConfigGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToList(); + } + return dbResult; + } + public void Dispose() { } @@ -97,24 +154,6 @@ namespace MP.Data.Controllers return dbResult; } - /// - /// Elenco da tabella Macchine - /// - /// - public List ConfigGetAll() - { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(_configuration)) - { - dbResult = dbCtx - .DbSetConfig - .AsNoTracking() - .OrderBy(x => x.Chiave) - .ToList(); - } - return dbResult; - } - /// /// Elenco da tabella MappaStatoExpl /// @@ -161,5 +200,13 @@ namespace MP.Data.Controllers } #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.Data/DatabaseModels/AnagGruppi.cs b/MP.Data/DatabaseModels/AnagGruppi.cs new file mode 100644 index 00000000..bab7168a --- /dev/null +++ b/MP.Data/DatabaseModels/AnagGruppi.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +#nullable disable + +namespace MP.Data.DatabaseModels +{ + [Table("AnagraficaGruppi")] + public partial class AnagGruppi + { + #region Public Properties + + //[Key, DatabaseGenerated(DatabaseGeneratedOption.None), MaxLength(50)] + public string CodGruppo { get; set; } + + //[MaxLength(50)] + public string TipoGruppo { get; set; } + + //[MaxLength(250)] + public string DescrGruppo { get; set; } + + public bool SelEnabled { get; set; } + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index e0706089..93db85e8 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -39,6 +39,7 @@ namespace MP.Data public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetMSE { get; set; } public virtual DbSet DbSetConfig { get; set; } + public virtual DbSet DbSetAnagGruppi { get; set; } #endregion Public Properties @@ -258,6 +259,28 @@ namespace MP.Data .HasColumnName("valoreStd") .HasComment("Valore di default/riferimento per la variabile"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.CodGruppo); + + //entity.ToTable("AnagraficaGruppi"); + + entity.Property(e => e.CodGruppo) + .HasMaxLength(50) + .HasColumnName("CodGruppo"); + + entity.Property(e => e.TipoGruppo) + .HasMaxLength(50) + .HasColumnName("TipoGruppo"); + + entity.Property(e => e.DescrGruppo) + .HasMaxLength(250) + .HasColumnName("DescrGruppo"); + + entity.Property(e => e.SelEnabled) + .HasColumnName("SelEnabled"); + + }); OnModelCreatingPartial(modelBuilder); }