Files
lux/EgwCoreLib.Lux.Data/Services/Report/ReportService.cs
T
2026-05-29 19:21:45 +02:00

74 lines
2.1 KiB
C#

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}.GetAllAsync", 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
}
}