Gestite schede nella pagina ispezione e migliorie grafiche

This commit is contained in:
2026-02-23 10:12:36 +01:00
parent b39b7ba751
commit efefd3499b
21 changed files with 253 additions and 37 deletions

View File

@@ -8,11 +8,11 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
{
public Task<Ispezione?> GetIspezioneAsync(string codMdep, DateOnly data, string rilevatore) =>
db.Ispezioni
.Include(x => x.Schede)
.FirstOrDefaultAsync(x =>
x.CodMdep == codMdep &&
x.Data == data &&
x.Rilevatore == rilevatore);
.Include(x => x.Schede)
.FirstOrDefaultAsync(x =>
x.CodMdep == codMdep &&
x.Data == data &&
x.Rilevatore == rilevatore);
public Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync() =>
db.Ispezioni
@@ -30,7 +30,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
public async Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore)
{
var existing = await db.Ispezioni
.Include(x => x.Schede)
.AsNoTracking()
.FirstOrDefaultAsync(x =>
x.CodMdep == codMdep &&
x.Data == data &&
@@ -48,8 +48,20 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
db.Ispezioni.Add(created);
await db.SaveChangesAsync();
return await db.Ispezioni
.AsNoTracking()
.FirstAsync(x =>
x.CodMdep == codMdep &&
x.Data == data &&
x.Rilevatore == rilevatore);
}
return created;
public async Task<bool> UpdateIspezioneAsync(Ispezione ispezione)
{
db.Ispezioni.Update(ispezione);
await db.SaveChangesAsync();
return true;
}
/// <summary>
@@ -84,16 +96,24 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
await db.SaveChangesAsync();
}
public Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore) =>
db.Schede
.AsNoTracking()
.Where(x => x.CodMdep == codMdep &&
x.Data == data &&
x.Rilevatore == rilevatore)
.ToListAsync();
public Task<Scheda?> GetSchedaAsync(int schedaId) =>
db.Schede
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == schedaId);
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == schedaId);
public Task<Scheda?> GetSchedaWithIspezioneAsync(int schedaId) =>
db.Schede
.Include(x => x.Ispezione)
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == schedaId);
.Include(x => x.Ispezione)
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == schedaId);
public async Task<bool> DeleteSchedaAsync(int schedaId)
{
@@ -106,6 +126,17 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
return true;
}
public async Task<bool> UpdateSchedaAsync(Scheda scheda)
{
var exists = await db.Schede.AnyAsync(x => x.Id == scheda.Id);
if (!exists)
return false;
db.Schede.Update(scheda);
await db.SaveChangesAsync();
return true;
}
/// <summary>
/// Cancella tutte le schede di una ispezione senza cancellare l'ispezione.
/// </summary>