Inizio setup repository
This commit is contained in:
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per IOC
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddIocDataLayer(this IServiceCollection services)
|
||||
{
|
||||
// Repository Singleton
|
||||
@@ -31,6 +39,48 @@ namespace MP.Data
|
||||
services.TryAddScoped<IStatsAggrService, StatsAggrService>();
|
||||
services.TryAddScoped<IStatsDetailService, StatsDetailService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
/// <summary>
|
||||
/// Aggiunta repository/servizi specifici per SPEC
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddSpecDataLayer(this IServiceCollection services)
|
||||
{
|
||||
// ---------- Start Repository ----------
|
||||
// Singleton
|
||||
services.TryAddSingleton<IAnagRepository, AnagRepository>();
|
||||
|
||||
// Scoped
|
||||
|
||||
|
||||
// ---------- End Repository ----------
|
||||
|
||||
|
||||
// ---------- Start Servizi ----------
|
||||
|
||||
// Singleton
|
||||
|
||||
// Scoped
|
||||
|
||||
// ---------- End Servizi ----------
|
||||
|
||||
|
||||
// ---------- Start Altro ----------
|
||||
// Singleton
|
||||
services.TryAddSingleton<AppAuthService>();
|
||||
services.TryAddSingleton<ListSelectDataSrv>();
|
||||
services.TryAddSingleton<SharedMemService>();
|
||||
services.TryAddSingleton<TabDataService>();
|
||||
services.TryAddSingleton<TabDataFeeder>();
|
||||
|
||||
// Scoped
|
||||
services.AddScoped<ISessionStorageService, SessionStorageService>();
|
||||
services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
|
||||
// ---------- End Altro ----------
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AnagCountersModel> AnagCountersGetNextAsync(string cntType);
|
||||
Task<List<vSelEventiBCodeModel>> AnagEventiGeneralAsync();
|
||||
Task<bool> AnagGruppiDeleteAsync(AnagGruppiModel updRec);
|
||||
Task<bool> AnagGruppiUpsertAsync(AnagGruppiModel UpdRec);
|
||||
Task<List<ListValuesModel>> AnagStatiCommAsync();
|
||||
Task<List<ListValuesModel>> AnagTipoArtLvAsync();
|
||||
Task<List<string>> ArticleWithDossierAsync();
|
||||
Task<int> ArticoliCountSearchAsync(string tipo = "*", string azienda = "*", string searchVal = "");
|
||||
Task<List<AnagArticoliModel>> ArticoliGetByTipoAsync(string tipo, string azienda = "*");
|
||||
Task<List<AnagArticoliModel>> ArticoliGetSearchAsync(int numRecord, string tipoArt, string azienda, string searchVal);
|
||||
Task<List<AnagArticoliModel>> ArticoliInKitAsync();
|
||||
Task<bool> ArticoliDeleteRecord(AnagArticoliModel currRec);
|
||||
Task<bool> ArticoliUpdateRecord(AnagArticoliModel currRec);
|
||||
Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName);
|
||||
Task<List<MacchineModel>> MacchineByMatrOper(int MatrOpr);
|
||||
Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo);
|
||||
Task<Dictionary<string, string>> VocabolarioGetLang(string lingua);
|
||||
Task<bool> VocabolarioUpsertAsync(VocabolarioModel upsRec);
|
||||
}
|
||||
}
|
||||
@@ -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<MoonProContext> ctxFactory) : base(ctxFactory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<AnagCountersModel> 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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<vSelEventiBCodeModel>> 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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiAziendeAsync()
|
||||
{
|
||||
return await AnagGruppiGetTipoAsync("AZIENDA");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiFaseAsync()
|
||||
{
|
||||
return await AnagGruppiGetTipoAsync("FASE");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagGruppiModel>> AnagGruppiGetTipoAsync(string tipoGruppo)
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetAnagGruppi
|
||||
.Where(x => x.TipoGruppo == tipoGruppo)
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.CodGruppo)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<RepartiDTO>> 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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ListValuesModel>> AnagStatiCommAsync()
|
||||
{
|
||||
return await ListValuesFiltAsync("PODL", "StatoComm");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ListValuesModel>> AnagTipoArtLvAsync()
|
||||
{
|
||||
return await ListValuesFiltAsync("AnagArticoli", "Tipo");
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <inheritdoc />
|
||||
public async Task<List<string>> ArticleWithDossierAsync()
|
||||
{
|
||||
using var dbCtx = new MoonPro_FluxContext(_configuration);
|
||||
return await dbCtx
|
||||
.DbSetDossiers
|
||||
.AsNoTracking()
|
||||
.Select(i => i.CodArticolo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<int> ArticoliCountAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.CountAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<int> ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "")
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
IQueryable<AnagArticoliModel> 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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> 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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "")
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
IQueryable<AnagArticoliModel> 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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetUnusedAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_ART_getNotUsed").AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliGetUsedAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_ART_getUsed").AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<AnagArticoliModel>> ArticoliInKitAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetArticoli.FromSqlRaw("EXEC stp_TempKIT_getArtChild").AsNoTracking().ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<ListValuesModel>> 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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> 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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<MacchineModel>> 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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds)
|
||||
{
|
||||
if (missingIds == null || !missingIds.Any())
|
||||
return new Dictionary<int, int>();
|
||||
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx
|
||||
.DbSetPODL
|
||||
.AsNoTracking()
|
||||
.Where(x => missingIds.Contains(x.IdxOdl))
|
||||
.ToDictionaryAsync(x => x.IdxOdl, x => x.IdxPromessa);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero dizionario traduzioni da cache o DB
|
||||
/// </summary>
|
||||
/// <param name="lingua">Codice lingua</param>
|
||||
/// <returns>Dizionario di traduzioni</returns>
|
||||
public async Task<Dictionary<string, string>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<MoonProContext> _ctxFactory;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonProContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Stacca un nuovo counter x il tipo richiesto
|
||||
/// </summary>
|
||||
/// <param name="cntType">Tipo di contatore</param>
|
||||
/// <returns>Modello del contatore aggiornato</returns>
|
||||
Task<AnagCountersModel> AnagCountersGetNextAsync(string cntType);
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce l'anagrafica EVENTI generalmente disponibile per OGNI macchina
|
||||
/// </summary>
|
||||
/// <param name="TableName">Nome Table x filtro (std: EvList)</param>
|
||||
/// <param name="FieldName">Nome Field x filtro (std: Common)</param>
|
||||
/// <returns>Lista di eventi generali</returns>
|
||||
Task<List<vSelEventiBCodeModel>> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo Azienda
|
||||
/// </summary>
|
||||
/// <returns>Lista di modelli anagrafica gruppi</returns>
|
||||
Task<List<AnagGruppiModel>> AnagGruppiAziendeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Delete record AnagraficaGruppi
|
||||
/// </summary>
|
||||
/// <param name="updRec">Record da eliminare</param>
|
||||
/// <returns>True se l'eliminazione è avvenuta</returns>
|
||||
Task<bool> AnagGruppiDeleteAsync(AnagGruppiModel updRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo Fasi
|
||||
/// </summary>
|
||||
/// <returns>Lista di modelli anagrafica gruppi</returns>
|
||||
Task<List<AnagGruppiModel>> AnagGruppiFaseAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gruppi x tipo modalità Async
|
||||
/// </summary>
|
||||
/// <param name="tipoGruppo">Tipo di gruppo (es. REPARTO, FASE, AZIENDA)</param>
|
||||
/// <returns>Lista di modelli anagrafica gruppi</returns>
|
||||
Task<List<AnagGruppiModel>> AnagGruppiGetTipoAsync(string tipoGruppo);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Gruppi tipo REPARTO (x associazione Macchine-Operatori) in formato DTO con conteggi del numero record trovati
|
||||
/// </summary>
|
||||
/// <returns>Lista di DTO reparti con conteggio macchine e operatori</returns>
|
||||
Task<List<RepartiDTO>> AnagGruppiRepartoDtoAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Upsert record AnagraficaGruppi (solo codice/descrizione)
|
||||
/// </summary>
|
||||
/// <param name="updRec">Record da inserire o aggiornare</param>
|
||||
/// <returns>True se l'operazione è riuscita</returns>
|
||||
Task<bool> AnagGruppiUpsertAsync(AnagGruppiModel updRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x Stati commessa (es Yacht Baglietto)
|
||||
/// </summary>
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> AnagStatiCommAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x Tipo articoli
|
||||
/// </summary>
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> AnagTipoArtLvAsync();
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco codice articoli che abbiano dati Dossier
|
||||
/// </summary>
|
||||
/// <returns>Lista di codici articolo</returns>
|
||||
Task<List<string>> ArticleWithDossierAsync();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio num articoli Async
|
||||
/// </summary>
|
||||
/// <returns>Conteggio totale articoli</returns>
|
||||
Task<int> ArticoliCountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio articoli data condizione ricerca
|
||||
/// </summary>
|
||||
/// <param name="tipoArt">Tipo articolo</param>
|
||||
/// <param name="azienda">Azienda</param>
|
||||
/// <param name="searchVal">Valore di ricerca</param>
|
||||
/// <returns>Conteggio risultati ricerca</returns>
|
||||
Task<int> ArticoliCountSearchAsync(string tipoArt = "*", string azienda = "*", string searchVal = "");
|
||||
|
||||
/// <summary>
|
||||
/// Eliminazione Record Articolo
|
||||
/// </summary>
|
||||
/// <param name="currRec">Record da eliminare</param>
|
||||
/// <returns>True se eliminato</returns>
|
||||
Task<bool> ArticoliDeleteRecordAsync(AnagArticoliModel currRec);
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce elenco articoli dato tipo (es KIT)
|
||||
/// </summary>
|
||||
/// <param name="tipo">Tipo articolo (es. KIT)</param>
|
||||
/// <param name="azienda">Azienda (opzionale)</param>
|
||||
/// <returns>Lista di articoli per tipo</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetByTipoAsync(string tipo, string azienda = "*");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli da filtro
|
||||
/// </summary>
|
||||
/// <param name="numRecord">Numero massimo di record</param>
|
||||
/// <param name="tipoArt">Tipo articolo</param>
|
||||
/// <param name="azienda">Azienda</param>
|
||||
/// <param name="searchVal">Valore di ricerca</param>
|
||||
/// <returns>Lista di articoli cercati</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetSearchAsync(int numRecord, string tipoArt = "*", string azienda = "*", string searchVal = "");
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli NON IMPIEGATI (da stored stp_ART_getUsed) Async
|
||||
/// </summary>
|
||||
/// <returns>Lista di articoli non impiegati</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetUnusedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Articoli IMPIEGATI (da stored stp_ART_getUsed) Async
|
||||
/// </summary>
|
||||
/// <returns>Lista di articoli impiegati</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliGetUsedAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Articoli che sono in KIT Child
|
||||
/// </summary>
|
||||
/// <returns>Lista di articoli in kit</returns>
|
||||
Task<List<AnagArticoliModel>> ArticoliInKitAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Update Record Articolo
|
||||
/// </summary>
|
||||
/// <param name="editRec">Record da aggiornare</param>
|
||||
/// <returns>True se aggiornato</returns>
|
||||
Task<bool> ArticoliUpdateRecord(AnagArticoliModel editRec);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco valori ammessi x tabella/colonna Async
|
||||
/// </summary>
|
||||
/// <param name="tabName">Nome tabella</param>
|
||||
/// <param name="fieldName">Nome colonna</param>
|
||||
/// <returns>Lista di valori ammessi</returns>
|
||||
Task<List<ListValuesModel>> ListValuesFiltAsync(string tabName, string fieldName);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Macchine dato operatore secondo gruppi (macchine/operatore)
|
||||
/// </summary>
|
||||
/// <param name="MatrOpr">Matricola operatore</param>
|
||||
/// <returns>Lista di macchine</returns>
|
||||
Task<List<MacchineModel>> MacchineByMatrOperAsync(int MatrOpr);
|
||||
|
||||
/// <summary>
|
||||
/// Elenco da tabella Macchine filtro x gruppo
|
||||
/// </summary>
|
||||
/// <param name="codGruppo">Codice gruppo</param>
|
||||
/// <returns>Lista di macchine</returns>
|
||||
Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo);
|
||||
|
||||
/// <summary>
|
||||
/// Dizionario associazione ODL/PODL
|
||||
/// </summary>
|
||||
/// <param name="missingIds">Lista di ID mancanti</param>
|
||||
/// <returns>Dizionario di associazione</returns>
|
||||
Task<Dictionary<int, int>> PODL_getDictOdlPodlAsync(List<int> missingIds);
|
||||
|
||||
/// <summary>
|
||||
/// Recupero dizionario traduzioni da cache o DB
|
||||
/// </summary>
|
||||
/// <param name="lingua">Codice lingua</param>
|
||||
/// <returns>Dizionario di traduzioni</returns>
|
||||
Task<Dictionary<string, string>> VocabolarioGetLangAsync(string lingua);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MP.Data.Repository.Anag
|
||||
{
|
||||
public interface IBaseRepository
|
||||
{
|
||||
//Task<DataLayerContext> CreateContextAsync();
|
||||
//Task<bool> SaveChangesAsync(DataLayerContext ctx);
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,7 @@ namespace MP.Data.Repository.IOC
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory)
|
||||
=> _ctxFactory = ctxFactory;
|
||||
protected BaseRepository(IDbContextFactory<MoonProContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
@@ -24,24 +23,8 @@ namespace MP.Data.Repository.IOC
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonProContext> CreateContextAsync()
|
||||
=> await _ctxFactory.CreateDbContextAsync();
|
||||
protected async Task<MoonProContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Salvataggio dati asincrono
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> SaveChangesAsync(DataLayerContext ctx)
|
||||
=> await ctx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
|
||||
#if false
|
||||
protected readonly DataLayerContext _dbCtx;
|
||||
protected BaseRepository(DataLayerContext db) => _dbCtx = db;
|
||||
public async Task<bool> SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,7 @@ namespace MP.Data.Repository.Utils
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory)
|
||||
=> _ctxFactory = ctxFactory;
|
||||
protected BaseRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory) => _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
@@ -24,24 +23,9 @@ namespace MP.Data.Repository.Utils
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonPro_UtilsContext> CreateContextAsync()
|
||||
=> await _ctxFactory.CreateDbContextAsync();
|
||||
protected async Task<MoonPro_UtilsContext> CreateContextAsync() => await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Salvataggio dati asincrono
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> SaveChangesAsync(DataLayerContext ctx)
|
||||
=> await ctx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
|
||||
#if false
|
||||
protected readonly DataLayerContext _dbCtx;
|
||||
protected BaseRepository(DataLayerContext db) => _dbCtx = db;
|
||||
public async Task<bool> SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>8.16.2606.113</Version>
|
||||
<Version>8.16.2606.116</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 8.16.2606.113</h4>
|
||||
<h4>Versione: 8.16.2606.116</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.113
|
||||
8.16.2606.116
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.113</version>
|
||||
<version>8.16.2606.116</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -103,8 +103,7 @@ namespace MP.SPEC.Components
|
||||
}
|
||||
}
|
||||
|
||||
MDService.ActionSetReqAsync(CurrAction);
|
||||
await Task.Delay(1);
|
||||
await MDService.ActionSetReqAsync(CurrAction);
|
||||
// se fatto --> ricarico!
|
||||
if (fatto)
|
||||
{
|
||||
|
||||
@@ -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<bool>("Otel:EnableTracing", false);
|
||||
slowLogThresh = _configuration.GetValue<double>("ServerConf:slowLogThresh", 1);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.SPEC</RootNamespace>
|
||||
<Version>8.16.2606.113</Version>
|
||||
<Version>8.16.2606.116</Version>
|
||||
<UserSecretsId>1800a78a-6ff1-40f9-b490-87fb8bfc1394</UserSecretsId>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<div class="col-4">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-success" @onclick="() => sendMessage()">SEND MESSAGE</button>
|
||||
<button class="btn btn-success" @onclick="() => SendMessageAsync()">SEND MESSAGE</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-warning" @onclick="() => clearMessage()">CLEAR</button>
|
||||
|
||||
@@ -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
|
||||
|
||||
+23
-6
@@ -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<MoonProContext>(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<MpDataService>();
|
||||
builder.Services.AddSingleton<ListSelectDataSrv>();
|
||||
builder.Services.AddSingleton<IOApiService>();
|
||||
builder.Services.AddSingleton<AppAuthService>();
|
||||
builder.Services.AddScoped<MsgServiceSpec>();
|
||||
|
||||
#if false
|
||||
builder.Services.AddSingleton<AppAuthService>();
|
||||
builder.Services.AddSingleton<ListSelectDataSrv>();
|
||||
builder.Services.AddSingleton<SharedMemService>();
|
||||
builder.Services.AddSingleton<TabDataService>();
|
||||
builder.Services.AddSingleton<TabDataFeeder>();
|
||||
builder.Services.AddSingleton<TabDataFeeder>();
|
||||
#endif
|
||||
|
||||
#if false
|
||||
// aggiunta helper local/session storage service
|
||||
builder.Services.AddScoped<ISessionStorageService, SessionStorageService>();
|
||||
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
||||
#endif
|
||||
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MAPOSPEC </i>
|
||||
<h4>Versione: 8.16.2606.113</h4>
|
||||
<h4>Versione: 8.16.2606.116</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.113
|
||||
8.16.2606.116
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.113</version>
|
||||
<version>8.16.2606.116</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user