diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 2ff337b3..f649a7a0 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -1,9 +1,12 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using MP.AppAuth.Services; using MP.Data.Controllers; +using MP.Data.Repository.Anag; using MP.Data.Repository.IOC; using MP.Data.Repository.Mtc; using MP.Data.Repository.Utils; +using MP.Data.Services; using MP.Data.Services.IOC; using MP.Data.Services.Mtc; using MP.Data.Services.Utils; @@ -12,6 +15,11 @@ namespace MP.Data { public static class DataServiceCollectionExtensions { + /// + /// Aggiunta repository/servizi specifici per IOC + /// + /// + /// public static IServiceCollection AddIocDataLayer(this IServiceCollection services) { // Repository Singleton @@ -31,6 +39,48 @@ namespace MP.Data services.TryAddScoped(); services.TryAddScoped(); + return services; + } + /// + /// Aggiunta repository/servizi specifici per SPEC + /// + /// + /// + public static IServiceCollection AddSpecDataLayer(this IServiceCollection services) + { + // ---------- Start Repository ---------- + // Singleton + services.TryAddSingleton(); + + // Scoped + + + // ---------- End Repository ---------- + + + // ---------- Start Servizi ---------- + + // Singleton + + // Scoped + + // ---------- End Servizi ---------- + + + // ---------- Start Altro ---------- + // Singleton + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + + // Scoped + services.AddScoped(); + services.AddScoped(); + + // ---------- End Altro ---------- + return services; } } diff --git a/MP.Data/Repositories/IAnagRepository.cs b/MP.Data/Repositories/IAnagRepository.cs deleted file mode 100644 index 8cbbbc98..00000000 --- a/MP.Data/Repositories/IAnagRepository.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using MP.Core.DTO; -using MP.Core.Objects; -using MP.Data.DbModels; -using NLog; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Threading.Tasks; - -namespace MP.Data.Repositories -{ - public interface IAnagRepository - { - Task AnagCountersGetNextAsync(string cntType); - Task> AnagEventiGeneralAsync(); - Task AnagGruppiDeleteAsync(AnagGruppiModel updRec); - Task AnagGruppiUpsertAsync(AnagGruppiModel UpdRec); - Task> AnagStatiCommAsync(); - Task> AnagTipoArtLvAsync(); - Task> ArticleWithDossierAsync(); - Task ArticoliCountSearchAsync(string tipo = "*", string azienda = "*", string searchVal = ""); - Task> ArticoliGetByTipoAsync(string tipo, string azienda = "*"); - Task> ArticoliGetSearchAsync(int numRecord, string tipoArt, string azienda, string searchVal); - Task> ArticoliInKitAsync(); - Task ArticoliDeleteRecord(AnagArticoliModel currRec); - Task ArticoliUpdateRecord(AnagArticoliModel currRec); - Task> ListValuesFiltAsync(string tabName, string fieldName); - Task> MacchineByMatrOper(int MatrOpr); - Task> MacchineGetFiltAsync(string codGruppo); - Task> VocabolarioGetLang(string lingua); - Task VocabolarioUpsertAsync(VocabolarioModel upsRec); - } -} diff --git a/MP.Data/Repository/Anag/AnagRepository.cs b/MP.Data/Repository/Anag/AnagRepository.cs new file mode 100644 index 00000000..c68cd626 --- /dev/null +++ b/MP.Data/Repository/Anag/AnagRepository.cs @@ -0,0 +1,417 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using MP.Core.DTO; +using MP.Data.DbModels; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Anag +{ + public class AnagRepository : BaseRepository, IAnagRepository + { + public AnagRepository(IDbContextFactory ctxFactory) : base(ctxFactory) + { + } + + /// + public async Task AnagCountersGetNextAsync(string cntType) + { + AnagCountersModel answ = new AnagCountersModel(); + await using var dbCtx = await CreateContextAsync(); + bool outTable = true; + if (outTable) + { + var pCntType = new SqlParameter("@CntType", cntType); + var pLastNum = new SqlParameter + { + ParameterName = "@LastNum", + SqlDbType = SqlDbType.Int, + Direction = ParameterDirection.Output + }; + + var dbResult = await dbCtx + .DbSetAnagCount + .FromSqlRaw("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT", pCntType, pLastNum) + .AsNoTracking() + .FirstOrDefaultAsync(); + if (dbResult != null) + { + answ = dbResult; + } + } + else + { + var pCntType = new SqlParameter("@CntType", cntType); + var pLastNum = new SqlParameter + { + ParameterName = "@LastNum", + SqlDbType = SqlDbType.Int, + Direction = ParameterDirection.Output + }; + var pCntCode = new SqlParameter + { + ParameterName = "@CntCode", + SqlDbType = SqlDbType.NVarChar, + Direction = ParameterDirection.Output + }; + var dbResult = await dbCtx + .Database + .ExecuteSqlRawAsync("EXEC dbo.stp_getNextNumb @CntType, @LastNum OUTPUT, @CntCode OUTPUT", pCntType, pLastNum, pCntCode); + if (dbResult != 0) + { + answ.CntType = cntType; + answ.CntCode = $"{pCntCode.Value}"; + int lNum = 0; + int.TryParse($"{pLastNum.Value}", out lNum); + answ.LastNum = lNum; + } + } + return answ; + } + + /// + public async Task> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common") + { + await using var dbCtx = await CreateContextAsync(); + var pTableName = new SqlParameter("@TableName", TableName); + var pFieldName = new SqlParameter("@FieldName", FieldName); + var dbResult = await dbCtx + .DbSetVSEB + .FromSqlRaw("exec dbo.stp_vseb_getGenerallyAvailable @TableName, @FieldName", pTableName, pFieldName) + .AsNoTracking() + .ToListAsync(); + return dbResult ?? new(); + } + + /// + public async Task> AnagGruppiAziendeAsync() + { + return await AnagGruppiGetTipoAsync("AZIENDA"); + } + + /// + public async Task AnagGruppiDeleteAsync(AnagGruppiModel updRec) + { + await using var dbCtx = await CreateContextAsync(); + var dbRec = await dbCtx + .DbSetAnagGruppi + .AsNoTracking() + .Where(x => x.CodGruppo == updRec.CodGruppo) + .FirstOrDefaultAsync(); + if (dbRec != null) + { + dbCtx.DbSetAnagGruppi.Remove(dbRec); + } + var numRes = await dbCtx.SaveChangesAsync(); + return numRes != 0; + } + + /// + public async Task> AnagGruppiFaseAsync() + { + return await AnagGruppiGetTipoAsync("FASE"); + } + + /// + public async Task> AnagGruppiGetTipoAsync(string tipoGruppo) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx + .DbSetAnagGruppi + .Where(x => x.TipoGruppo == tipoGruppo) + .AsNoTracking() + .OrderBy(x => x.CodGruppo) + .ToListAsync(); + } + + /// + public async Task> AnagGruppiRepartoDtoAsync() + { + await using var dbCtx = await CreateContextAsync(); + var listReparti = await AnagGruppiGetTipoAsync("REPARTO"); + + var listMacc = await dbCtx + .DbSetGrp2Macc + .AsNoTracking() + .ToListAsync(); + var listOpr = await dbCtx + .DbSetGrp2Oper + .AsNoTracking() + .ToListAsync(); + + return listReparti + .Select(x => new RepartiDTO() + { + CodGruppo = x.CodGruppo, + TipoGruppo = x.TipoGruppo, + DescrGruppo = x.DescrGruppo, + SelEnabled = x.SelEnabled, + CountMacc = listMacc.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.IdxMacchina).Distinct().Count(), + CountOpr = listOpr.Where(y => y.CodGruppo == x.CodGruppo).Select(y => y.MatrOpr).Distinct().Count() + }) + .ToList(); + } + + /// + public async Task AnagGruppiUpsertAsync(AnagGruppiModel updRec) + { + await using var dbCtx = await CreateContextAsync(); + var dbRec = await dbCtx + .DbSetAnagGruppi + .AsNoTracking() + .Where(x => x.CodGruppo == updRec.CodGruppo) + .FirstOrDefaultAsync(); + if (dbRec != null) + { + dbRec.DescrGruppo = updRec.DescrGruppo; + dbCtx.Entry(dbRec).State = EntityState.Modified; + } + else + { + await dbCtx.DbSetAnagGruppi.AddAsync(updRec); + } + var numRes = await dbCtx.SaveChangesAsync(); + return numRes != 0; + } + + /// + public async Task> AnagStatiCommAsync() + { + return await ListValuesFiltAsync("PODL", "StatoComm"); + } + + /// + public async Task> AnagTipoArtLvAsync() + { + return await ListValuesFiltAsync("AnagArticoli", "Tipo"); + } + +#if false + /// + public async Task> ArticleWithDossierAsync() + { + using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetDossiers + .AsNoTracking() + .Select(i => i.CodArticolo) + .Distinct() + .ToListAsync(); + } +#endif + + /// + public async Task ArticoliCountAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetArticoli.CountAsync(); + } + + /// + public async Task ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "") + { + await using var dbCtx = await CreateContextAsync(); + IQueryable query = dbCtx.DbSetArticoli.AsNoTracking(); + + if (tipoArt != "*") + { + query = query.Where(x => EF.Functions.Like(x.Tipo, tipoArt)); + } + if (azienda != "*") + { + query = query.Where(x => EF.Functions.Like(x.Azienda, azienda)); + } + if (!string.IsNullOrWhiteSpace(searchVal)) + { + string pattern = $"%{searchVal}%"; + query = query.Where(x => + EF.Functions.Like(x.CodArticolo, pattern) || + EF.Functions.Like(x.DescArticolo, pattern) || + EF.Functions.Like(x.Disegno, pattern)); + } + + return await query.OrderBy(x => x.CodArticolo).CountAsync(); + } + + /// + public async Task ArticoliDeleteRecordAsync(AnagArticoliModel currRec) + { + await using var dbCtx = await CreateContextAsync(); + var currVal = await dbCtx + .DbSetArticoli + .Where(x => x.CodArticolo == currRec.CodArticolo) + .FirstOrDefaultAsync(); + if (currVal != null) + { + dbCtx.DbSetArticoli.Remove(currVal); + return await dbCtx.SaveChangesAsync() > 0; + } + return false; + } + + /// + public async Task> ArticoliGetByTipoAsync(string tipo, string azienda = "*") + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx + .DbSetArticoli + .AsNoTracking() + .Where(x => x.Tipo.ToUpper() == tipo.ToUpper() && (azienda == "*" || x.Azienda.ToUpper() == azienda.ToUpper())) + .OrderBy(x => x.CodArticolo) + .ToListAsync(); + } + + /// + public async Task> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "") + { + await using var dbCtx = await CreateContextAsync(); + IQueryable query = dbCtx.DbSetArticoli.AsNoTracking(); + + if (tipoArt != "*") + { + query = query.Where(x => EF.Functions.Like(x.Tipo, tipoArt)); + } + if (azienda != "*") + { + query = query.Where(x => EF.Functions.Like(x.Azienda, azienda)); + } + if (!string.IsNullOrWhiteSpace(searchVal)) + { + string pattern = $"%{searchVal}%"; + query = query.Where(x => + EF.Functions.Like(x.CodArticolo, pattern) || + EF.Functions.Like(x.DescArticolo, pattern) || + EF.Functions.Like(x.Disegno, pattern)); + } + + return await query.OrderBy(x => x.CodArticolo).Take(numRecord).ToListAsync(); + } + + /// + public async Task> ArticoliGetUnusedAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_ART_getNotUsed").AsNoTracking().ToListAsync(); + } + + /// + public async Task> ArticoliGetUsedAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_ART_getUsed").AsNoTracking().ToListAsync(); + } + + /// + public async Task> ArticoliInKitAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_TempKIT_getArtChild").AsNoTracking().ToListAsync(); + } + + /// + public async Task ArticoliUpdateRecord(AnagArticoliModel editRec) + { + await using var dbCtx = await CreateContextAsync(); + var currRec = await dbCtx.DbSetArticoli.FirstOrDefaultAsync(x => x.CodArticolo == editRec.CodArticolo); + if (currRec != null) + { + currRec.Disegno = editRec.Disegno; + currRec.DescArticolo = editRec.DescArticolo; + currRec.Tipo = editRec.Tipo; + currRec.Azienda = editRec.Azienda; + dbCtx.Entry(currRec).State = EntityState.Modified; + return await dbCtx.SaveChangesAsync() > 0; + } + return false; + } + + /// + public async Task> ListValuesFiltAsync(string tabName, string fieldName) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetListValues + .Where(x => x.TableName == tabName && x.FieldName == fieldName) + .AsNoTracking() + .OrderBy(x => x.ordinal) + .ToListAsync(); + } + + /// + public async Task> MacchineByMatrOperAsync(int MatrOpr) + { + await using var dbCtx = await CreateContextAsync(); + if (MatrOpr == 0) + { + return await dbCtx.DbSetMacchine.AsNoTracking().OrderBy(x => x.IdxMacchina).ToListAsync(); + } + else + { + return await dbCtx.DbSetGrp2Oper + .Where(g => g.MatrOpr == MatrOpr) + .Join(dbCtx.DbSetGrp2Macc, g => g.CodGruppo, m => m.CodGruppo, (g, m) => m) + .Distinct() + .Join(dbCtx.DbSetMacchine, g => g.IdxMacchina, m => m.IdxMacchina, (g, m) => m) + .Distinct() + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + } + + /// + public async Task> MacchineGetFiltAsync(string codGruppo) + { + await using var dbCtx = await CreateContextAsync(); + if (codGruppo == "*") + { + return await dbCtx.DbSetMacchine.AsNoTracking().OrderBy(x => x.IdxMacchina).ToListAsync(); + } + else + { + return await dbCtx.DbSetGrp2Macc + .Where(g => g.CodGruppo == codGruppo) + .Join(dbCtx.DbSetMacchine, g => g.IdxMacchina, m => m.IdxMacchina, (g, m) => m) + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToListAsync(); + } + } + + /// + public async Task> PODL_getDictOdlPodlAsync(List missingIds) + { + if (missingIds == null || !missingIds.Any()) + return new Dictionary(); + + await using var dbCtx = await CreateContextAsync(); + return await dbCtx + .DbSetPODL + .AsNoTracking() + .Where(x => missingIds.Contains(x.IdxOdl)) + .ToDictionaryAsync(x => x.IdxOdl, x => x.IdxPromessa); + } + + /// + /// Recupero dizionario traduzioni da cache o DB + /// + /// Codice lingua + /// Dizionario di traduzioni + public async Task> VocabolarioGetLangAsync(string lingua) + { + await using var dbCtx = await CreateContextAsync(); + var rawList = dbCtx + .DbSetVocabolario + .AsNoTracking() + .Where(x => x.Lingua.ToLower() == lingua.ToLower()) + .OrderBy(x => x.Lemma) + .ToList(); + // Proietto in dizionario + return rawList + .DistinctBy(t => t.Lemma, StringComparer.OrdinalIgnoreCase) + .ToDictionary(t => t.Lemma, t => t.Traduzione, StringComparer.OrdinalIgnoreCase); + } + } +} diff --git a/MP.Data/Repository/Anag/BaseRepository.cs b/MP.Data/Repository/Anag/BaseRepository.cs new file mode 100644 index 00000000..bc26dc68 --- /dev/null +++ b/MP.Data/Repository/Anag/BaseRepository.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Anag +{ + public abstract class BaseRepository : IBaseRepository + { + #region Protected Fields + + protected readonly IDbContextFactory _ctxFactory; + + #endregion Protected Fields + + #region Protected Constructors + + protected BaseRepository(IDbContextFactory ctxFactory) => _ctxFactory = ctxFactory; + + #endregion Protected Constructors + + #region Protected Methods + + /// + /// Creazione dbcontext per singola transazione + /// + /// + protected async Task CreateContextAsync() => await _ctxFactory.CreateDbContextAsync(); + + #endregion Protected Methods + + } +} \ No newline at end of file diff --git a/MP.Data/Repository/Anag/IAnagRepository.cs b/MP.Data/Repository/Anag/IAnagRepository.cs new file mode 100644 index 00000000..e817d469 --- /dev/null +++ b/MP.Data/Repository/Anag/IAnagRepository.cs @@ -0,0 +1,186 @@ +using MP.Core.DTO; +using MP.Data.DbModels; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MP.Data.Repository.Anag +{ + public interface IAnagRepository + { + /// + /// Stacca un nuovo counter x il tipo richiesto + /// + /// Tipo di contatore + /// Modello del contatore aggiornato + Task AnagCountersGetNextAsync(string cntType); + + /// + /// Restituisce l'anagrafica EVENTI generalmente disponibile per OGNI macchina + /// + /// Nome Table x filtro (std: EvList) + /// Nome Field x filtro (std: Common) + /// Lista di eventi generali + Task> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common"); + + /// + /// Elenco Gruppi tipo Azienda + /// + /// Lista di modelli anagrafica gruppi + Task> AnagGruppiAziendeAsync(); + + /// + /// Delete record AnagraficaGruppi + /// + /// Record da eliminare + /// True se l'eliminazione è avvenuta + Task AnagGruppiDeleteAsync(AnagGruppiModel updRec); + + /// + /// Elenco Gruppi tipo Fasi + /// + /// Lista di modelli anagrafica gruppi + Task> AnagGruppiFaseAsync(); + + /// + /// Gruppi x tipo modalità Async + /// + /// Tipo di gruppo (es. REPARTO, FASE, AZIENDA) + /// Lista di modelli anagrafica gruppi + Task> AnagGruppiGetTipoAsync(string tipoGruppo); + + /// + /// Elenco Gruppi tipo REPARTO (x associazione Macchine-Operatori) in formato DTO con conteggi del numero record trovati + /// + /// Lista di DTO reparti con conteggio macchine e operatori + Task> AnagGruppiRepartoDtoAsync(); + + /// + /// Upsert record AnagraficaGruppi (solo codice/descrizione) + /// + /// Record da inserire o aggiornare + /// True se l'operazione è riuscita + Task AnagGruppiUpsertAsync(AnagGruppiModel updRec); + + /// + /// Elenco valori ammessi x Stati commessa (es Yacht Baglietto) + /// + /// Lista di valori ammessi + Task> AnagStatiCommAsync(); + + /// + /// Elenco valori ammessi x Tipo articoli + /// + /// Lista di valori ammessi + Task> AnagTipoArtLvAsync(); + +#if false + /// + /// Elenco codice articoli che abbiano dati Dossier + /// + /// Lista di codici articolo + Task> ArticleWithDossierAsync(); +#endif + + /// + /// Conteggio num articoli Async + /// + /// Conteggio totale articoli + Task ArticoliCountAsync(); + + /// + /// Conteggio articoli data condizione ricerca + /// + /// Tipo articolo + /// Azienda + /// Valore di ricerca + /// Conteggio risultati ricerca + Task ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = ""); + + /// + /// Eliminazione Record Articolo + /// + /// Record da eliminare + /// True se eliminato + Task ArticoliDeleteRecordAsync(AnagArticoliModel currRec); + + /// + /// Restituisce elenco articoli dato tipo (es KIT) + /// + /// Tipo articolo (es. KIT) + /// Azienda (opzionale) + /// Lista di articoli per tipo + Task> ArticoliGetByTipoAsync(string tipo, string azienda = "*"); + + /// + /// Elenco tabella Articoli da filtro + /// + /// Numero massimo di record + /// Tipo articolo + /// Azienda + /// Valore di ricerca + /// Lista di articoli cercati + Task> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = ""); + + /// + /// Elenco tabella Articoli NON IMPIEGATI (da stored stp_ART_getUsed) Async + /// + /// Lista di articoli non impiegati + Task> ArticoliGetUnusedAsync(); + + /// + /// Elenco tabella Articoli IMPIEGATI (da stored stp_ART_getUsed) Async + /// + /// Lista di articoli impiegati + Task> ArticoliGetUsedAsync(); + + /// + /// Elenco Articoli che sono in KIT Child + /// + /// Lista di articoli in kit + Task> ArticoliInKitAsync(); + + /// + /// Update Record Articolo + /// + /// Record da aggiornare + /// True se aggiornato + Task ArticoliUpdateRecord(AnagArticoliModel editRec); + + /// + /// Elenco valori ammessi x tabella/colonna Async + /// + /// Nome tabella + /// Nome colonna + /// Lista di valori ammessi + Task> ListValuesFiltAsync(string tabName, string fieldName); + + /// + /// Elenco Macchine dato operatore secondo gruppi (macchine/operatore) + /// + /// Matricola operatore + /// Lista di macchine + Task> MacchineByMatrOperAsync(int MatrOpr); + + /// + /// Elenco da tabella Macchine filtro x gruppo + /// + /// Codice gruppo + /// Lista di macchine + Task> MacchineGetFiltAsync(string codGruppo); + + /// + /// Dizionario associazione ODL/PODL + /// + /// Lista di ID mancanti + /// Dizionario di associazione + Task> PODL_getDictOdlPodlAsync(List missingIds); + + /// + /// Recupero dizionario traduzioni da cache o DB + /// + /// Codice lingua + /// Dizionario di traduzioni + Task> VocabolarioGetLangAsync(string lingua); + + } +} diff --git a/MP.Data/Repository/Anag/IBaseRepository.cs b/MP.Data/Repository/Anag/IBaseRepository.cs new file mode 100644 index 00000000..246d20f6 --- /dev/null +++ b/MP.Data/Repository/Anag/IBaseRepository.cs @@ -0,0 +1,8 @@ +namespace MP.Data.Repository.Anag +{ + public interface IBaseRepository + { + //Task CreateContextAsync(); + //Task SaveChangesAsync(DataLayerContext ctx); + } +} diff --git a/MP.Data/Repository/IOC/BaseRepository.cs b/MP.Data/Repository/IOC/BaseRepository.cs index 7814ee85..50877a21 100644 --- a/MP.Data/Repository/IOC/BaseRepository.cs +++ b/MP.Data/Repository/IOC/BaseRepository.cs @@ -13,8 +13,7 @@ namespace MP.Data.Repository.IOC #region Protected Constructors - protected BaseRepository(IDbContextFactory ctxFactory) - => _ctxFactory = ctxFactory; + protected BaseRepository(IDbContextFactory ctxFactory) => _ctxFactory = ctxFactory; #endregion Protected Constructors @@ -24,24 +23,8 @@ namespace MP.Data.Repository.IOC /// Creazione dbcontext per singola transazione /// /// - protected async Task CreateContextAsync() - => await _ctxFactory.CreateDbContextAsync(); + protected async Task CreateContextAsync() => await _ctxFactory.CreateDbContextAsync(); #endregion Protected Methods - -#if false - /// - /// Salvataggio dati asincrono - /// - /// - protected async Task SaveChangesAsync(DataLayerContext ctx) - => await ctx.SaveChangesAsync() > 0; -#endif - -#if false - protected readonly DataLayerContext _dbCtx; - protected BaseRepository(DataLayerContext db) => _dbCtx = db; - public async Task SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0; -#endif } } \ No newline at end of file diff --git a/MP.Data/Repository/Utils/BaseRepository.cs b/MP.Data/Repository/Utils/BaseRepository.cs index 4e709040..aceaa04a 100644 --- a/MP.Data/Repository/Utils/BaseRepository.cs +++ b/MP.Data/Repository/Utils/BaseRepository.cs @@ -13,8 +13,7 @@ namespace MP.Data.Repository.Utils #region Protected Constructors - protected BaseRepository(IDbContextFactory ctxFactory) - => _ctxFactory = ctxFactory; + protected BaseRepository(IDbContextFactory ctxFactory) => _ctxFactory = ctxFactory; #endregion Protected Constructors @@ -24,24 +23,9 @@ namespace MP.Data.Repository.Utils /// Creazione dbcontext per singola transazione /// /// - protected async Task CreateContextAsync() - => await _ctxFactory.CreateDbContextAsync(); + protected async Task CreateContextAsync() => await _ctxFactory.CreateDbContextAsync(); #endregion Protected Methods -#if false - /// - /// Salvataggio dati asincrono - /// - /// - protected async Task SaveChangesAsync(DataLayerContext ctx) - => await ctx.SaveChangesAsync() > 0; -#endif - -#if false - protected readonly DataLayerContext _dbCtx; - protected BaseRepository(DataLayerContext db) => _dbCtx = db; - public async Task SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0; -#endif } } \ No newline at end of file diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 4b13e62b..892725f7 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.113 + 8.16.2606.116 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 386f99ae..793b3777 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 8.16.2606.113

+

Versione: 8.16.2606.116


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index 142014de..87293708 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.113 +8.16.2606.116 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 62319e01..4818c638 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.113 + 8.16.2606.116 https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html false diff --git a/MP.SPEC/Components/AskCloseOdl.razor.cs b/MP.SPEC/Components/AskCloseOdl.razor.cs index 85fe627e..2a78e714 100644 --- a/MP.SPEC/Components/AskCloseOdl.razor.cs +++ b/MP.SPEC/Components/AskCloseOdl.razor.cs @@ -103,8 +103,7 @@ namespace MP.SPEC.Components } } - MDService.ActionSetReqAsync(CurrAction); - await Task.Delay(1); + await MDService.ActionSetReqAsync(CurrAction); // se fatto --> ricarico! if (fatto) { diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index c95bce5c..a80da490 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -6,6 +6,7 @@ using MP.Data; using MP.Data.Controllers; using MP.Data.DbModels; using MP.Data.MgModels; +using MP.Data.Repository.Anag; using MP.Data.Services; using Newtonsoft.Json; using NLog; @@ -20,11 +21,14 @@ namespace MP.SPEC.Data { #region Public Constructors - public MpDataService(IConfiguration configuration, IFusionCache cache) + private readonly IAnagRepository _anagRepository; + + public MpDataService(IConfiguration configuration, IFusionCache cache, IAnagRepository anagRepository) { // salvataggio oggetti _configuration = configuration; _cache = cache; + _anagRepository = anagRepository; // Verifica conf trace... traceEnabled = _configuration.GetValue("Otel:EnableTracing", false); slowLogThresh = _configuration.GetValue("ServerConf:slowLogThresh", 1); diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 7dc37fbb..98dcf7d9 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2606.113 + 8.16.2606.116 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Pages/Test.razor b/MP.SPEC/Pages/Test.razor index 60775048..0febaf6d 100644 --- a/MP.SPEC/Pages/Test.razor +++ b/MP.SPEC/Pages/Test.razor @@ -29,7 +29,7 @@
    - +
    diff --git a/MP.SPEC/Pages/Test.razor.cs b/MP.SPEC/Pages/Test.razor.cs index 7f2957a3..8d495b95 100644 --- a/MP.SPEC/Pages/Test.razor.cs +++ b/MP.SPEC/Pages/Test.razor.cs @@ -38,8 +38,8 @@ namespace MP.SPEC.Pages CurrAction.IsActive = false; CurrAction.Topic = "Chiusura ODL"; CurrAction.Message = "Rilevato possibile fine operazioni, Vuoi chiudere la commessa?"; - MMDataService.ActionSetReqAsync(CurrAction); - await Task.Delay(1); + + await MMDataService.ActionSetReqAsync(CurrAction); } protected override async Task OnInitializedAsync() @@ -68,11 +68,11 @@ namespace MP.SPEC.Pages } } - protected void sendMessage() + protected async Task SendMessageAsync() { CurrAction.DtReq = DateTime.Now; CurrAction.IsActive = true; - MMDataService.ActionSetReqAsync(CurrAction); + await MMDataService.ActionSetReqAsync(CurrAction); } #endregion Protected Methods diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 997d8354..36036cdd 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -1,9 +1,10 @@ using Microsoft.AspNetCore.Authentication.Negotiate; using Microsoft.AspNetCore.StaticFiles; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.FileProviders; -using MP.AppAuth.Services; -using MP.Data.Services; +using MP.Data; using MP.SPEC.Components; using MP.SPEC.Data; using MP.SPEC.Services; @@ -155,20 +156,36 @@ builder.Services.AddFusionCache() ConnectionMultiplexerFactory = () => Task.FromResult(redisMultiplexer) })); +// Metodi principali x accesso dati +var connStr = builder.Configuration.GetConnectionString("MP.Data") + ?? throw new InvalidOperationException("ConnString 'MP.Data' mancante."); +// aggiungo il costruttore x i DbContextFactory +builder.Services.AddDbContextFactory(options => + options.UseSqlServer(connStr) + .EnableSensitiveDataLogging(false) // true solo in Sviluppo + .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); + +// MP.Data Services Utils - Statistiche DB +builder.Services.AddSpecDataLayer(); // altri servizi builder.Services.AddSingleton(); -builder.Services.AddSingleton(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); builder.Services.AddScoped(); + +#if false +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +#endif +#if false // aggiunta helper local/session storage service builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); +#endif builder.Services.AddHttpClient(); diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 91e3fb3c..3f744dfc 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

    Versione: 8.16.2606.113

    +

    Versione: 8.16.2606.116


    Note di rilascio:
    • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 142014de..87293708 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.113 +8.16.2606.116 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 1f1a8e1b..a0393e81 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.113 + 8.16.2606.116 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false