Gestiti salvataggi rest

This commit is contained in:
2026-03-02 10:50:34 +01:00
parent e027d8e5cf
commit ab9578a45f
58 changed files with 1235 additions and 305 deletions

View File

@@ -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 =>

View File

@@ -0,0 +1,148 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SteUp.Data.LocalDb;
#nullable disable
namespace SteUp.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260226155235_ModDataIspezione")]
partial class ModDataIspezione
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.3");
modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b =>
{
b.Property<string>("CodMdep")
.HasColumnType("TEXT");
b.Property<DateTime>("Data")
.HasColumnType("TEXT");
b.Property<string>("Rilevatore")
.HasColumnType("TEXT");
b.Property<int>("Stato")
.HasColumnType("INTEGER");
b.HasKey("CodMdep", "Data", "Rilevatore");
b.ToTable("Ispezioni");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ActivityTypeId")
.HasColumnType("TEXT");
b.Property<string>("CodJfas")
.HasColumnType("TEXT");
b.Property<string>("CodMdep")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("Data")
.HasColumnType("TEXT");
b.Property<string>("DescrizioneReparto")
.HasColumnType("TEXT");
b.Property<string>("ImageNames")
.HasColumnType("TEXT");
b.Property<string>("Note")
.HasColumnType("TEXT");
b.Property<string>("Responsabile")
.HasColumnType("TEXT");
b.Property<string>("Rilevatore")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Scadenza")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("CodMdep", "Data", "Rilevatore");
b.ToTable("Schede");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Barcode")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("TEXT");
b.Property<string>("Descrizione")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("SchedaId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SchedaId", "Barcode")
.IsUnique();
b.ToTable("SchedaArticoli");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b =>
{
b.HasOne("SteUp.Shared.Core.Entities.Ispezione", "Ispezione")
.WithMany("Schede")
.HasForeignKey("CodMdep", "Data", "Rilevatore")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Ispezione");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b =>
{
b.HasOne("SteUp.Shared.Core.Entities.Scheda", "Scheda")
.WithMany("Articoli")
.HasForeignKey("SchedaId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Scheda");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b =>
{
b.Navigation("Schede");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b =>
{
b.Navigation("Articoli");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SteUp.Data.Migrations
{
/// <inheritdoc />
public partial class ModDataIspezione : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@@ -0,0 +1,154 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SteUp.Data.LocalDb;
#nullable disable
namespace SteUp.Data.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260227102100_AddActivityId")]
partial class AddActivityId
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.3");
modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b =>
{
b.Property<string>("CodMdep")
.HasColumnType("TEXT");
b.Property<DateTime>("Data")
.HasColumnType("TEXT");
b.Property<string>("Rilevatore")
.HasColumnType("TEXT");
b.Property<string>("ActivityId")
.HasColumnType("TEXT");
b.Property<int>("Stato")
.HasColumnType("INTEGER");
b.HasKey("CodMdep", "Data", "Rilevatore");
b.ToTable("Ispezioni");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ActivityId")
.HasColumnType("TEXT");
b.Property<string>("ActivityTypeId")
.HasColumnType("TEXT");
b.Property<string>("CodJfas")
.HasColumnType("TEXT");
b.Property<string>("CodMdep")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("Data")
.HasColumnType("TEXT");
b.Property<string>("DescrizioneReparto")
.HasColumnType("TEXT");
b.Property<string>("ImageNames")
.HasColumnType("TEXT");
b.Property<string>("Note")
.HasColumnType("TEXT");
b.Property<string>("Responsabile")
.HasColumnType("TEXT");
b.Property<string>("Rilevatore")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Scadenza")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("CodMdep", "Data", "Rilevatore");
b.ToTable("Schede");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Barcode")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("TEXT");
b.Property<string>("Descrizione")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<int>("SchedaId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SchedaId", "Barcode")
.IsUnique();
b.ToTable("SchedaArticoli");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b =>
{
b.HasOne("SteUp.Shared.Core.Entities.Ispezione", "Ispezione")
.WithMany("Schede")
.HasForeignKey("CodMdep", "Data", "Rilevatore")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Ispezione");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b =>
{
b.HasOne("SteUp.Shared.Core.Entities.Scheda", "Scheda")
.WithMany("Articoli")
.HasForeignKey("SchedaId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Scheda");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b =>
{
b.Navigation("Schede");
});
modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b =>
{
b.Navigation("Articoli");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SteUp.Data.Migrations
{
/// <inheritdoc />
public partial class AddActivityId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ActivityId",
table: "Schede",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "ActivityId",
table: "Ispezioni",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ActivityId",
table: "Schede");
migrationBuilder.DropColumn(
name: "ActivityId",
table: "Ispezioni");
}
}
}

View File

@@ -22,12 +22,15 @@ namespace SteUp.Data.Migrations
b.Property<string>("CodMdep")
.HasColumnType("TEXT");
b.Property<DateOnly>("Data")
b.Property<DateTime>("Data")
.HasColumnType("TEXT");
b.Property<string>("Rilevatore")
.HasColumnType("TEXT");
b.Property<string>("ActivityId")
.HasColumnType("TEXT");
b.Property<int>("Stato")
.HasColumnType("INTEGER");
@@ -42,6 +45,9 @@ namespace SteUp.Data.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ActivityId")
.HasColumnType("TEXT");
b.Property<string>("ActivityTypeId")
.HasColumnType("TEXT");
@@ -52,7 +58,7 @@ namespace SteUp.Data.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateOnly>("Data")
b.Property<DateTime>("Data")
.HasColumnType("TEXT");
b.Property<string>("DescrizioneReparto")