Aggiunti repository + servizi x reports in LUX UI

This commit is contained in:
Samuele Locatelli
2026-04-24 17:42:49 +02:00
parent a9acd2ca69
commit c865420e95
19 changed files with 328 additions and 14 deletions
+1 -3
View File
@@ -1,6 +1,4 @@
using EgwCoreLib.Lux.Data.DbModel.Warehouse;
namespace EgwCoreLib.Lux.Data
namespace EgwCoreLib.Lux.Data
{
public partial class DataLayerContext : DbContext
{
+1
View File
@@ -7,6 +7,7 @@ global using EgwCoreLib.Lux.Data.DbModel.Cost;
global using EgwCoreLib.Lux.Data.DbModel.Items;
global using EgwCoreLib.Lux.Data.DbModel.Job;
global using EgwCoreLib.Lux.Data.DbModel.Production;
global using EgwCoreLib.Lux.Data.DbModel.Report;
global using EgwCoreLib.Lux.Data.DbModel.Sales;
global using EgwCoreLib.Lux.Data.DbModel.Stats;
global using EgwCoreLib.Lux.Data.DbModel.Stock;
+80
View File
@@ -0,0 +1,80 @@
namespace EgwCoreLib.Lux.Data
{
public partial class ReportContext : DbContext
{
private static Logger Log = LogManager.GetCurrentClassLogger();
private IConfiguration _configuration;
public ReportContext()
{
}
#if false
public ReportContext(IConfiguration configuration)
{
_configuration = configuration;
}
#endif
public ReportContext(DbContextOptions<ReportContext> options) : base(options)
{
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
{
Log.Error(exc, "Exception during context initialization 02");
}
}
public virtual DbSet<ReportModel> DbSetReports { get; set; }
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// default
string connString = DbConfig.CONNECTION_STRING;
if (string.IsNullOrEmpty(connString))
{
#if DEBUG
connString = "Server=mdb.ufficio;port=3306;database=Lux_000;uid=lux_user;pwd=Egal_pwd!;sslmode=None;";
//connString = "Server=mdb.ufficio;port=3306;database=Lux_000_dev;uid=lux_user;pwd=Egal_pwd!;sslmode=None;";
#else
connString = "Server=mdb.ufficio;port=3306;database=Lux_000;uid=lux_user;pwd=Egal_pwd!;sslmode=None;";
#endif
}
if (!optionsBuilder.IsConfigured)
{
var serverVersion = ServerVersion.AutoDetect(connString);
// 2026.01.09 aggiornata init componente POMELO
#if false
optionsBuilder.UseMySql(connString, serverVersion);
#endif
optionsBuilder.UseMySql(connString, serverVersion, options =>
{
// Questo abilita il supporto JSON specifico per MySQL
options.EnableStringComparisonTranslations();
});
// verificare setup componente
#if false
optionsBuilder
.UseMySql(connString, serverVersion)
.UseSnakeCaseNamingConvention(); // via EFCore.NamingConventions
#endif
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}
}
}
}
@@ -0,0 +1,31 @@
namespace EgwCoreLib.Lux.Data.Repository.Report
{
public abstract class BaseRepRepository : IBaseRepRepository
{
#region Protected Fields
protected readonly IDbContextFactory<ReportContext> _ctxFactory;
#endregion Protected Fields
#region Protected Constructors
protected BaseRepRepository(IDbContextFactory<ReportContext> ctxFactory)
=> _ctxFactory = ctxFactory;
#endregion Protected Constructors
#region Protected Methods
/// <summary>
/// Creazione dbcontext per singola transazione
/// </summary>
/// <returns></returns>
protected async Task<ReportContext> CreateContextAsync()
=> await _ctxFactory.CreateDbContextAsync();
#endregion Protected Methods
}
}
@@ -0,0 +1,10 @@
namespace EgwCoreLib.Lux.Data.Repository.Report
{
public interface IBaseRepRepository
{
//Task<DataLayerContext> CreateContextAsync();
//Task<bool> SaveChangesAsync(DataLayerContext ctx);
}
}
@@ -0,0 +1,32 @@
namespace EgwCoreLib.Lux.Data.Repository.Report
{
public interface IReportRepository
{
#region Public Methods
/// <summary>
/// Inserisce un nuovo record Report nel database.
/// </summary>
/// <param name="entity">Record da inserire</param>
Task<bool> AddAsync(ReportModel entity);
/// <summary>
/// Recupera l'elenco completo dei Report
/// </summary>
Task<List<ReportModel>> GetAllAsync();
/// <summary>
/// Recupera un Report specifico per ID.
/// </summary>
/// <param name="currID">ID da recuperare</param>
Task<ReportModel?> GetByIdAsync(int currID);
/// <summary>
/// Aggiorna un record Report esistente nel database.
/// </summary>
/// <param name="entity">Record aggiornato</param>
Task<bool> UpdateAsync(ReportModel entity);
#endregion Public Methods
}
}
@@ -0,0 +1,64 @@
namespace EgwCoreLib.Lux.Data.Repository.Report
{
public class ReportRepository : BaseRepRepository, IReportRepository
{
#region Public Constructors
public ReportRepository(IDbContextFactory<ReportContext> ctxFactory) : base(ctxFactory)
{
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc />
public async Task<bool> AddAsync(ReportModel entity)
{
await using var dbCtx = await CreateContextAsync();
// per ora disabilito salvataggio effettivo in prod
#if DEBUG
await dbCtx.DbSetReports.AddAsync(entity);
#endif
return await dbCtx.SaveChangesAsync() > 0;
}
/// <inheritdoc />
public async Task<List<ReportModel>> GetAllAsync()
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetReports
.AsNoTracking()
.ToListAsync();
}
/// <inheritdoc />
public async Task<ReportModel?> GetByIdAsync(int currID)
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetReports.FirstOrDefaultAsync(x => x.ReportID == currID);
}
/// <inheritdoc />
public async Task<bool> UpdateAsync(ReportModel entity)
{
await using var dbCtx = await CreateContextAsync();
// Recuperiamo l'entità tracciata dal context
var trackedEntity = await dbCtx.DbSetReports.FirstOrDefaultAsync(x => x.ReportID == entity.ReportID);
if (trackedEntity != null)
{
// Aggiorna i valori dell'entità tracciata con quelli della nuova
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
}
else
{
dbCtx.DbSetReports.Update(entity);
}
return await dbCtx.SaveChangesAsync() > 0;
}
#endregion Public Methods
}
}
@@ -0,0 +1,24 @@
namespace EgwCoreLib.Lux.Data.Services.Report
{
public interface IReportService
{
#region Public Methods
/// <summary>
/// Elenco completo Report da DB
/// </summary>
/// <returns></returns>
Task<List<ReportModel>> GetAllAsync();
/// <summary>
/// Upsert record Report
/// </summary>
/// <param name="updRec"></param>
/// <returns></returns>
Task<bool> UpsertAsync(ReportModel upsRec);
#endregion Public Methods
}
}
@@ -0,0 +1,74 @@
using EgwCoreLib.Lux.Data.Repository.Report;
namespace EgwCoreLib.Lux.Data.Services.Report
{
public class ReportService : BaseServ, IReportService
{
#region Public Constructors
public ReportService(
IConfiguration config,
IConnectionMultiplexer redis,
IReportRepository repo) : base(config, redis)
{
_className = "Report";
_repo = repo;
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc />
public async Task<List<ReportModel>> GetAllAsync()
{
// Uso helper TraceAsync che gestisce automaticamente StartActivity, Log e Exception tracking
return await TraceAsync($"{_className}.GetAll", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:ALL",
async () => await _repo.GetAllAsync()
);
});
}
/// <inheritdoc />
public async Task<bool> UpsertAsync(ReportModel upsRec)
{
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetByIdAsync(upsRec.ReportID);
string operation = "UPDATE";
bool success = false;
if (currRec != null)
{
success = await _repo.UpdateAsync(upsRec);
}
else
{
operation = "INSERT";
success = await _repo.AddAsync(upsRec);
}
activity?.SetTag("db.operation", operation);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
});
}
#endregion Public Methods
#region Private Fields
private readonly string _className;
private readonly IReportRepository _repo;
#endregion Private Fields
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.1.2604.2416</Version>
<Version>1.1.2604.2417</Version>
</PropertyGroup>
<ItemGroup>
@@ -2,7 +2,7 @@
namespace Lux.Report.Data.Repository
{
public abstract class BaseRepository : IBaseRepository
public abstract class BaseRepRepository : IBaseRepRepository
{
#region Protected Fields
@@ -12,7 +12,7 @@ namespace Lux.Report.Data.Repository
#region Protected Constructors
protected BaseRepository(IDbContextFactory<ReportContext> ctxFactory)
protected BaseRepRepository(IDbContextFactory<ReportContext> ctxFactory)
=> _ctxFactory = ctxFactory;
#endregion Protected Constructors
@@ -2,7 +2,7 @@
namespace Lux.Report.Data.Repository
{
public interface IBaseRepository
public interface IBaseRepRepository
{
//Task<DataLayerContext> CreateContextAsync();
//Task<bool> SaveChangesAsync(DataLayerContext ctx);
@@ -2,7 +2,7 @@
namespace Lux.Report.Data.Repository
{
public class ReportRepository : BaseRepository, IReportRepository
public class ReportRepository : BaseRepRepository, IReportRepository
{
#region Public Constructors
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.1.2604.2416</Version>
<Version>1.1.2604.2417</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.1.2604.2416</Version>
<Version>1.1.2604.2417</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50</UserSecretsId>
<Version>1.1.2604.2416</Version>
<Version>1.1.2604.2417</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>LUX - Web Windows MES</i>
<h4>Versione: 1.1.2604.2416</h4>
<h4>Versione: 1.1.2604.2417</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.1.2604.2416
1.1.2604.2417
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2604.2416</version>
<version>1.1.2604.2417</version>
<url>http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>