Gestiti salvataggi rest
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SteUp.Shared.Core.Entities;
|
||||
using SteUp.Shared.Core.Enum;
|
||||
using SteUp.Shared.Core.Helpers;
|
||||
using SteUp.Shared.Core.Interface.LocalDb;
|
||||
|
||||
namespace SteUp.Data.LocalDb.EntityServices;
|
||||
|
||||
public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
{
|
||||
public Task<Ispezione?> GetIspezioneAsync(string codMdep, DateOnly data, string rilevatore) =>
|
||||
public Task<Ispezione?> GetIspezioneAsync(string codMdep, DateTime data, string rilevatore) =>
|
||||
db.Ispezioni
|
||||
.Include(x => x.Schede)
|
||||
.ThenInclude(s => s.Articoli)
|
||||
@@ -29,7 +31,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore)
|
||||
public async Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore)
|
||||
{
|
||||
var existing = await db.Ispezioni
|
||||
.AsNoTracking()
|
||||
@@ -65,11 +67,46 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
await db.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, StatusEnum stato)
|
||||
{
|
||||
var ispezione = await db.Ispezioni
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.CodMdep == codMdep &&
|
||||
x.Data == data &&
|
||||
x.Rilevatore == rilevatore);
|
||||
|
||||
if (ispezione is null)
|
||||
return false;
|
||||
|
||||
ispezione.Stato = stato;
|
||||
db.Ispezioni.Update(ispezione);
|
||||
await db.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateActivityIdIspezioneAsync(string codMdep, DateTime data, string rilevatore,
|
||||
string? activityId)
|
||||
{
|
||||
var ispezione = await db.Ispezioni
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.CodMdep == codMdep &&
|
||||
x.Data == data &&
|
||||
x.Rilevatore == rilevatore);
|
||||
|
||||
if (ispezione is null)
|
||||
return false;
|
||||
|
||||
ispezione.ActivityId = activityId;
|
||||
db.Ispezioni.Update(ispezione);
|
||||
await db.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancella l'ispezione e tutte le schede collegate (e relativi articoli via cascade).
|
||||
/// </summary>
|
||||
public async Task<bool> DeleteIspezioneAsync(string codMdep, DateOnly data, string rilevatore)
|
||||
public async Task<bool> DeleteIspezioneAsync(string codMdep, DateTime data, string rilevatore)
|
||||
{
|
||||
var ispezione = await db.Ispezioni
|
||||
.FirstOrDefaultAsync(x =>
|
||||
@@ -85,7 +122,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task AddSchedaAsync(string codMdep, DateOnly data, string rilevatore, Scheda scheda)
|
||||
public async Task AddSchedaAsync(string codMdep, DateTime data, string rilevatore, Scheda scheda)
|
||||
{
|
||||
await GetOrCreateIspezioneAsync(codMdep, data, rilevatore);
|
||||
|
||||
@@ -105,7 +142,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore) =>
|
||||
public Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore) =>
|
||||
db.Schede
|
||||
.AsNoTracking()
|
||||
.Include(s => s.Articoli)
|
||||
@@ -127,6 +164,17 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.Id == schedaId);
|
||||
|
||||
public async Task<bool> UpdateActivityIdSchedaAsync(int schedaId, string? activityId)
|
||||
{
|
||||
var scheda = await db.Schede.FirstOrDefaultAsync(x => x.Id == schedaId);
|
||||
if (scheda is null) return false;
|
||||
|
||||
scheda.ActivityId = activityId;
|
||||
db.Schede.Update(scheda);
|
||||
await db.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteSchedaAsync(int schedaId)
|
||||
{
|
||||
var scheda = await db.Schede.FirstOrDefaultAsync(x => x.Id == schedaId);
|
||||
@@ -197,7 +245,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService
|
||||
/// <summary>
|
||||
/// Cancella tutte le schede di una ispezione senza cancellare l'ispezione.
|
||||
/// </summary>
|
||||
public async Task<int> DeleteAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore)
|
||||
public async Task<int> DeleteAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore)
|
||||
{
|
||||
var schede = await db.Schede
|
||||
.Where(s =>
|
||||
|
||||
Reference in New Issue
Block a user