using Lux.Report.Data.DbModel; namespace Lux.Report.Data.Repository { public class ReportRepository : BaseRepRepository, IReportRepository { #region Public Constructors public ReportRepository(IDbContextFactory ctxFactory) : base(ctxFactory) { } #endregion Public Constructors #region Public Methods /// public async Task 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; } /// public async Task> GetAllAsync() { await using var dbCtx = await CreateContextAsync(); return await dbCtx.DbSetReports .AsNoTracking() .ToListAsync(); } /// public async Task GetByIdAsync(int currID) { await using var dbCtx = await CreateContextAsync(); return await dbCtx.DbSetReports.FirstOrDefaultAsync(x => x.ReportID == currID); } /// public async Task 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 } }