Merge branch 'feature/MigrateDataLayerService' of https://gitlab.steamware.net/etis/lux into feature/MigrateDataLayerService
This commit is contained in:
@@ -50,54 +50,6 @@ namespace EgwCoreLib.Lux.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo Customers da DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal List<CustomerModel> CustomersGetAll()
|
||||
{
|
||||
List<CustomerModel> dbResult = new List<CustomerModel>();
|
||||
//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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo Dealers da DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal List<DealerModel> DealersGetAll()
|
||||
{
|
||||
List<DealerModel> dbResult = new List<DealerModel>();
|
||||
//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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add item ricevuti da BOM calcolata
|
||||
/// </summary>
|
||||
|
||||
@@ -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<DataLayerContext> ctxFactory) : base(ctxFactory)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public async Task<List<CustomerModel>> GetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetCustomer
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -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<DataLayerContext> ctxFactory) : base(ctxFactory)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public async Task<List<DealerModel>> GetAllAsync()
|
||||
{
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
return await dbCtx.DbSetDealer
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
||||
|
||||
namespace EgwCoreLib.Lux.Data.Repository.Sales
|
||||
{
|
||||
public interface ICustomerRepository
|
||||
{
|
||||
Task<List<CustomerModel>> GetAllAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
||||
|
||||
namespace EgwCoreLib.Lux.Data.Repository.Sales
|
||||
{
|
||||
public interface IDealerRepository
|
||||
{
|
||||
Task<List<DealerModel>> GetAllAsync();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -107,124 +107,6 @@ namespace EgwCoreLib.Lux.Data.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elenco contatori
|
||||
/// </summary>
|
||||
/// <param name="yearRef">Anno riferimento, se null da tutti</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CounterModel>> CountersGetAllAsync(int? yearRef = null)
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB";
|
||||
List<CounterModel>? result = new List<CounterModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:ConfEnvir";
|
||||
RedisValue rawData = await _redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<CounterModel>>($"{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<CounterModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera un nuovo valore del contatore per tipo ed anno richiesto, se mancasse crea
|
||||
/// </summary>
|
||||
/// <param name="yearRef">Anno riferimento</param>
|
||||
/// <param name="countName">Counter richiesto</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> 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
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo Customers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<CustomerModel> CustomersGetAll()
|
||||
{
|
||||
using var activity = StartActivity();
|
||||
string source = "DB";
|
||||
List<CustomerModel>? result = new List<CustomerModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:Customers:ALL";
|
||||
RedisValue rawData = _redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<CustomerModel>>($"{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<CustomerModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo dealers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<DealerModel> DealersGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
using var activity = StartActivity();
|
||||
List<DealerModel>? result = new List<DealerModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{redisBaseKey}:Dealers:ALL";
|
||||
RedisValue rawData = _redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<DealerModel>>($"{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<DealerModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset completo cache sistema
|
||||
/// </summary>
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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<List<CustomerModel>> 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
|
||||
}
|
||||
}
|
||||
@@ -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<List<DealerModel>> 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
||||
|
||||
namespace EgwCoreLib.Lux.Data.Services.Sales
|
||||
{
|
||||
public interface ICustomerService
|
||||
{
|
||||
Task<List<CustomerModel>> GetAllAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
||||
|
||||
namespace EgwCoreLib.Lux.Data.Services.Sales
|
||||
{
|
||||
public interface IDealerService
|
||||
{
|
||||
Task<List<DealerModel>> GetAllAsync();
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
|
||||
/// <returns></returns>
|
||||
public async Task<int> 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}",
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -178,6 +178,8 @@ builder.Services.AddScoped<DataLayerServices>();
|
||||
builder.Services.AddScoped<IConfGlassRepository, ConfGlassRepository>();
|
||||
builder.Services.AddScoped<IConfProfileRepository, ConfProfileRepository>();
|
||||
builder.Services.AddScoped<IConfWoodRepository, ConfWoodRepository>();
|
||||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
builder.Services.AddScoped<IDealerRepository, DealerRepository>();
|
||||
builder.Services.AddScoped<IEnvirParamRepository, EnvirParamRepository>();
|
||||
builder.Services.AddScoped<IGenClassRepository, GenClassRepository>();
|
||||
builder.Services.AddScoped<IGenValRepository, GenValRepository>();
|
||||
@@ -200,6 +202,8 @@ builder.Services.AddScoped<ITemplateRowRepository, TemplateRowRepository>();
|
||||
builder.Services.AddScoped<IConfGlassService, ConfGlassService>();
|
||||
builder.Services.AddScoped<IConfProfileService, ConfProfileService>();
|
||||
builder.Services.AddScoped<IConfWoodService, ConfWoodService>();
|
||||
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||
builder.Services.AddScoped<IDealerService, DealerService>();
|
||||
builder.Services.AddScoped<IEnvirParamService, EnvirParamService>();
|
||||
builder.Services.AddScoped<IGenClassService, GenClassService>();
|
||||
builder.Services.AddScoped<IGenValService, GenValService>();
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Servizi di accesso ai dati iniettati dal framework.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
protected DataLayerServices DLService { get; set; } = null!;
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Chiamato automaticamente all'inizializzazione del componente.
|
||||
/// </summary>
|
||||
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!;
|
||||
|
||||
/// <summary>
|
||||
/// Servizi di accesso ai dati iniettati dal framework.
|
||||
/// </summary>
|
||||
[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
|
||||
|
||||
@@ -216,6 +216,8 @@ builder.Services.AddScoped<DataLayerServices>();
|
||||
builder.Services.AddScoped<IConfGlassRepository, ConfGlassRepository>();
|
||||
builder.Services.AddScoped<IConfProfileRepository, ConfProfileRepository>();
|
||||
builder.Services.AddScoped<IConfWoodRepository, ConfWoodRepository>();
|
||||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
builder.Services.AddScoped<IDealerRepository, DealerRepository>();
|
||||
builder.Services.AddScoped<IEnvirParamRepository, EnvirParamRepository>();
|
||||
builder.Services.AddScoped<IGenClassRepository, GenClassRepository>();
|
||||
builder.Services.AddScoped<IGenValRepository, GenValRepository>();
|
||||
@@ -238,6 +240,8 @@ builder.Services.AddScoped<ITemplateRowRepository, TemplateRowRepository>();
|
||||
builder.Services.AddScoped<IConfGlassService, ConfGlassService>();
|
||||
builder.Services.AddScoped<IConfProfileService, ConfProfileService>();
|
||||
builder.Services.AddScoped<IConfWoodService, ConfWoodService>();
|
||||
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||
builder.Services.AddScoped<IDealerService, DealerService>();
|
||||
builder.Services.AddScoped<IEnvirParamService, EnvirParamService>();
|
||||
builder.Services.AddScoped<IGenClassService, GenClassService>();
|
||||
builder.Services.AddScoped<IGenValService, GenValService>();
|
||||
|
||||
Reference in New Issue
Block a user