diff --git a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs index 310c38ec..74964898 100644 --- a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs +++ b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs @@ -50,54 +50,6 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } - /// - /// Elenco completo Customers da DB - /// - /// - internal List CustomersGetAll() - { - List dbResult = new List(); - //using (DataLayerContext dbCtx = new DataLayerContext(_config)) - using (DataLayerContext dbCtx = new DataLayerContext()) - { - try - { - dbResult = dbCtx - .DbSetCustomer - .ToList(); - } - catch (Exception exc) - { - Log.Error($"Eccezione durante CustomersGetAll{Environment.NewLine}{exc}"); - } - } - return dbResult; - } - - /// - /// Elenco completo Dealers da DB - /// - /// - internal List DealersGetAll() - { - List dbResult = new List(); - //using (DataLayerContext dbCtx = new DataLayerContext(_config)) - using (DataLayerContext dbCtx = new DataLayerContext()) - { - try - { - dbResult = dbCtx - .DbSetDealer - .ToList(); - } - catch (Exception exc) - { - Log.Error($"Eccezione durante DealersGetAll{Environment.NewLine}{exc}"); - } - } - return dbResult; - } - /// /// Add item ricevuti da BOM calcolata /// diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/CustomerRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/CustomerRepository.cs new file mode 100644 index 00000000..b1de0ea4 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Sales/CustomerRepository.cs @@ -0,0 +1,28 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; +using Microsoft.EntityFrameworkCore; + +namespace EgwCoreLib.Lux.Data.Repository.Sales +{ + public class CustomerRepository : BaseRepository, ICustomerRepository + { + #region Public Constructors + + public CustomerRepository(IDbContextFactory ctxFactory) : base(ctxFactory) + { + } + + #endregion Public Constructors + + #region Public Methods + + public async Task> GetAllAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetCustomer + .AsNoTracking() + .ToListAsync(); + } + + #endregion Public Methods + } +} diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/DealerRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/DealerRepository.cs new file mode 100644 index 00000000..fa405afe --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Sales/DealerRepository.cs @@ -0,0 +1,28 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; +using Microsoft.EntityFrameworkCore; + +namespace EgwCoreLib.Lux.Data.Repository.Sales +{ + public class DealerRepository : BaseRepository, IDealerRepository + { + #region Public Constructors + + public DealerRepository(IDbContextFactory ctxFactory) : base(ctxFactory) + { + } + + #endregion Public Constructors + + #region Public Methods + + public async Task> GetAllAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetDealer + .AsNoTracking() + .ToListAsync(); + } + + #endregion Public Methods + } +} diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/ICustomerRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/ICustomerRepository.cs new file mode 100644 index 00000000..e19f1a16 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Sales/ICustomerRepository.cs @@ -0,0 +1,9 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; + +namespace EgwCoreLib.Lux.Data.Repository.Sales +{ + public interface ICustomerRepository + { + Task> GetAllAsync(); + } +} diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/IDealerRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/IDealerRepository.cs new file mode 100644 index 00000000..659d0170 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Sales/IDealerRepository.cs @@ -0,0 +1,9 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; + +namespace EgwCoreLib.Lux.Data.Repository.Sales +{ + public interface IDealerRepository + { + Task> GetAllAsync(); + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Config/ConfGlassService.cs b/EgwCoreLib.Lux.Data/Services/Config/ConfGlassService.cs index 9c0e1235..8edba4c9 100644 --- a/EgwCoreLib.Lux.Data/Services/Config/ConfGlassService.cs +++ b/EgwCoreLib.Lux.Data/Services/Config/ConfGlassService.cs @@ -48,7 +48,7 @@ namespace EgwCoreLib.Lux.Data.Services.Config return await TraceAsync($"{_className}.GetAll", async (activity) => { return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}", + $"{_redisBaseKey}:{_className}:ALL", async () => await _repo.GetAllAsync(), UltraLongCache ); diff --git a/EgwCoreLib.Lux.Data/Services/Config/ConfProfileService.cs b/EgwCoreLib.Lux.Data/Services/Config/ConfProfileService.cs index 844b0319..20623c3c 100644 --- a/EgwCoreLib.Lux.Data/Services/Config/ConfProfileService.cs +++ b/EgwCoreLib.Lux.Data/Services/Config/ConfProfileService.cs @@ -48,7 +48,7 @@ namespace EgwCoreLib.Lux.Data.Services.Config return await TraceAsync($"{_className}.GetAll", async (activity) => { return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}", + $"{_redisBaseKey}:{_className}:ALL", async () => await _repo.GetAllAsync(), UltraLongCache ); diff --git a/EgwCoreLib.Lux.Data/Services/Config/ConfWoodService.cs b/EgwCoreLib.Lux.Data/Services/Config/ConfWoodService.cs index fc300382..7a770266 100644 --- a/EgwCoreLib.Lux.Data/Services/Config/ConfWoodService.cs +++ b/EgwCoreLib.Lux.Data/Services/Config/ConfWoodService.cs @@ -48,7 +48,7 @@ namespace EgwCoreLib.Lux.Data.Services.Config return await TraceAsync($"{_className}.GetAll", async (activity) => { return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}", + $"{_redisBaseKey}:{_className} :ALL", async () => await _repo.GetAllAsync(), UltraLongCache ); diff --git a/EgwCoreLib.Lux.Data/Services/Config/EnvirParamService.cs b/EgwCoreLib.Lux.Data/Services/Config/EnvirParamService.cs index 8d8a43e1..0df807c1 100644 --- a/EgwCoreLib.Lux.Data/Services/Config/EnvirParamService.cs +++ b/EgwCoreLib.Lux.Data/Services/Config/EnvirParamService.cs @@ -28,7 +28,7 @@ namespace EgwCoreLib.Lux.Data.Services.Config return await TraceAsync($"{_className}.GetAll", async (activity) => { return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}", + $"{_redisBaseKey}:{_className}:ALL", async () => await _repo.GetAllAsync(), UltraLongCache ); diff --git a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs index d29b14d6..6fbacc86 100644 --- a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs +++ b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs @@ -107,124 +107,6 @@ namespace EgwCoreLib.Lux.Data.Services return result; } -#if false - /// - /// Elenco contatori - /// - /// Anno riferimento, se null da tutti - /// - public async Task> CountersGetAllAsync(int? yearRef = null) - { - using var activity = StartActivity(); - string source = "DB"; - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:ConfEnvir"; - RedisValue rawData = await _redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await dbController.CountersGetAllAsync(yearRef); - // serializzo e salvo con config x evitare loop... - rawData = JsonConvert.SerializeObject(result, JSSettings); - await _redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (result == null) - { - result = new List(); - } - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return result; - } - - /// - /// Recupera un nuovo valore del contatore per tipo ed anno richiesto, se mancasse crea - /// - /// Anno riferimento - /// Counter richiesto - /// - public async Task CountersGetNext(int yearRef, string countName) - { - using var activity = StartActivity(); - string source = "DB"; - int nextIdx = await dbController.CountersGetNext(yearRef, countName); - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return nextIdx; - } -#endif - - /// - /// Elenco completo Customers - /// - /// - public List CustomersGetAll() - { - using var activity = StartActivity(); - string source = "DB"; - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:Customers:ALL"; - RedisValue rawData = _redisDb.StringGet(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = dbController.CustomersGetAll(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - _redisDb.StringSet(currKey, rawData, UltraLongCache); - } - if (result == null) - { - result = new List(); - } - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return result; - } - - /// - /// Elenco completo dealers - /// - /// - public List DealersGetAll() - { - string source = "DB"; - using var activity = StartActivity(); - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:Dealers:ALL"; - RedisValue rawData = _redisDb.StringGet(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = dbController.DealersGetAll(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - _redisDb.StringSet(currKey, rawData, LongCache); - } - if (result == null) - { - result = new List(); - } - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return result; - } - /// /// Reset completo cache sistema /// diff --git a/EgwCoreLib.Lux.Data/Services/Production/ProductionPlantService.cs b/EgwCoreLib.Lux.Data/Services/Production/ProductionPlantService.cs index 0a7447c7..05f3a68a 100644 --- a/EgwCoreLib.Lux.Data/Services/Production/ProductionPlantService.cs +++ b/EgwCoreLib.Lux.Data/Services/Production/ProductionPlantService.cs @@ -27,7 +27,7 @@ namespace EgwCoreLib.Lux.Data.Services.Production return await TraceAsync($"{_className}.GetAll", async (activity) => { return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}", + $"{_redisBaseKey}:{_className}:ALL", async () => await _repo.GetAllAsync(), UltraLongCache ); diff --git a/EgwCoreLib.Lux.Data/Services/Sales/CustomerService.cs b/EgwCoreLib.Lux.Data/Services/Sales/CustomerService.cs new file mode 100644 index 00000000..781901bb --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Sales/CustomerService.cs @@ -0,0 +1,47 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; +using EgwCoreLib.Lux.Data.Repository.Sales; +using Microsoft.Extensions.Configuration; +using StackExchange.Redis; + +namespace EgwCoreLib.Lux.Data.Services.Sales +{ + public class CustomerService : BaseServ, ICustomerService + { + #region Public Constructors + + public CustomerService( + IConfiguration config, + IConnectionMultiplexer redis, + ICustomerRepository repo) : base(config, redis) + { + _className = "Customer"; + _repo = repo; + } + + #endregion Public Constructors + + #region Public Methods + + public async Task> 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(), + UltraLongCache + ); + }); + } + + #endregion Public Methods + + #region Private Fields + + private readonly string _className; + private readonly ICustomerRepository _repo; + + #endregion Private Fields + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Sales/DealerService.cs b/EgwCoreLib.Lux.Data/Services/Sales/DealerService.cs new file mode 100644 index 00000000..bf96b602 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Sales/DealerService.cs @@ -0,0 +1,47 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; +using EgwCoreLib.Lux.Data.Repository.Sales; +using Microsoft.Extensions.Configuration; +using StackExchange.Redis; + +namespace EgwCoreLib.Lux.Data.Services.Sales +{ + public class DealerService : BaseServ, IDealerService + { + #region Public Constructors + + public DealerService( + IConfiguration config, + IConnectionMultiplexer redis, + IDealerRepository repo) : base(config, redis) + { + _className = "Dealer"; + _repo = repo; + } + + #endregion Public Constructors + + #region Public Methods + + public async Task> 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(), + UltraLongCache + ); + }); + } + + #endregion Public Methods + + #region Private Fields + + private readonly string _className; + private readonly IDealerRepository _repo; + + #endregion Private Fields + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Sales/ICustomerService.cs b/EgwCoreLib.Lux.Data/Services/Sales/ICustomerService.cs new file mode 100644 index 00000000..bc104c9a --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Sales/ICustomerService.cs @@ -0,0 +1,9 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; + +namespace EgwCoreLib.Lux.Data.Services.Sales +{ + public interface ICustomerService + { + Task> GetAllAsync(); + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Sales/IDealerService.cs b/EgwCoreLib.Lux.Data/Services/Sales/IDealerService.cs new file mode 100644 index 00000000..48e8cf99 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Sales/IDealerService.cs @@ -0,0 +1,9 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; + +namespace EgwCoreLib.Lux.Data.Services.Sales +{ + public interface IDealerService + { + Task> GetAllAsync(); + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Utils/CounterService.cs b/EgwCoreLib.Lux.Data/Services/Utils/CounterService.cs index af993e6f..1de91727 100644 --- a/EgwCoreLib.Lux.Data/Services/Utils/CounterService.cs +++ b/EgwCoreLib.Lux.Data/Services/Utils/CounterService.cs @@ -47,7 +47,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils /// public async Task GetNextAsync(int yearRef, string countName) { - return await TraceAsync($"{_className}.GetAll", async (activity) => + return await TraceAsync($"{_className}.GetNextAsync", async (activity) => { return await GetOrSetCacheAsync( $"{_redisBaseKey}:{_className}:{countName}:Y{yearRef}", diff --git a/EgwCoreLib.Lux.Data/Services/Utils/GenClassService.cs b/EgwCoreLib.Lux.Data/Services/Utils/GenClassService.cs index b545eb3e..b2137d97 100644 --- a/EgwCoreLib.Lux.Data/Services/Utils/GenClassService.cs +++ b/EgwCoreLib.Lux.Data/Services/Utils/GenClassService.cs @@ -53,7 +53,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils return await TraceAsync($"{_className}.GetAll", async (activity) => { return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}", + $"{_redisBaseKey}:{_className}:ALL", async () => await _repo.GetAllAsync(), UltraLongCache ); diff --git a/Lux.API/Program.cs b/Lux.API/Program.cs index e6460a68..8c004992 100644 --- a/Lux.API/Program.cs +++ b/Lux.API/Program.cs @@ -178,6 +178,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -200,6 +202,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Lux.UI/Components/Compo/OfferMan.razor.cs b/Lux.UI/Components/Compo/OfferMan.razor.cs index 72dc4d30..865115a0 100644 --- a/Lux.UI/Components/Compo/OfferMan.razor.cs +++ b/Lux.UI/Components/Compo/OfferMan.razor.cs @@ -1,7 +1,7 @@ using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.Services; +using EgwCoreLib.Lux.Data.Services.Sales; using Microsoft.AspNetCore.Components; -using System.Threading.Tasks; namespace Lux.UI.Components.Compo { @@ -32,24 +32,15 @@ namespace Lux.UI.Components.Compo #endregion Public Properties - #region Protected Properties - - /// - /// Servizi di accesso ai dati iniettati dal framework. - /// - [Inject] - protected DataLayerServices DLService { get; set; } = null!; - - #endregion Protected Properties - #region Protected Methods /// /// Chiamato automaticamente all'inizializzazione del componente. /// - protected override void OnInitialized() + protected override async Task OnInitializedAsync() { - ReloadData(); + await ReloadData(); + await base.OnInitializedAsync(); } #endregion Protected Methods @@ -65,6 +56,22 @@ namespace Lux.UI.Components.Compo #endregion Private Fields + #region Private Properties + + [Inject] + private ICustomerService CService { get; set; } = null!; + + /// + /// Servizi di accesso ai dati iniettati dal framework. + /// + [Inject] + private DataLayerServices DLService { get; set; } = null!; + + [Inject] + private IDealerService DService { get; set; } = null!; + + #endregion Private Properties + #region Private Methods private Task DoCancel() @@ -78,10 +85,10 @@ namespace Lux.UI.Components.Compo return EC_Updated.InvokeAsync(CurrRecord); } - private void ReloadData() + private async Task ReloadData() { - CustomersList = DLService.CustomersGetAll(); - DealersList = DLService.DealersGetAll(); + CustomersList = await CService.GetAllAsync(); + DealersList = await DService.GetAllAsync(); } #endregion Private Methods diff --git a/Lux.UI/Program.cs b/Lux.UI/Program.cs index ec17cffb..66e03194 100644 --- a/Lux.UI/Program.cs +++ b/Lux.UI/Program.cs @@ -216,6 +216,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -238,6 +240,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped();