Implentata scansione barcode e lista articoli nel form scheda

This commit is contained in:
2026-02-26 15:46:49 +01:00
parent a5e27bcf06
commit e027d8e5cf
20 changed files with 770 additions and 19 deletions

View File

@@ -8,6 +8,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
{
public DbSet<Ispezione> Ispezioni => Set<Ispezione>();
public DbSet<Scheda> Schede => Set<Scheda>();
public DbSet<SchedaArticolo> SchedaArticoli => Set<SchedaArticolo>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -15,7 +16,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
modelBuilder.Entity<Ispezione>()
.HasKey(x => new { x.CodMdep, x.Data, x.Rilevatore });
modelBuilder.Entity<Scheda>()
.HasOne(x => x.Ispezione)
.WithMany(x => x.Schede)
@@ -31,5 +32,15 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
v => JsonSerializer.Deserialize<List<string>>(v, (JsonSerializerOptions?)null) ?? new List<string>()
);
modelBuilder.Entity<SchedaArticolo>()
.HasOne(a => a.Scheda)
.WithMany(s => s.Articoli)
.HasForeignKey(a => a.SchedaId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<SchedaArticolo>()
.HasIndex(a => new { a.SchedaId, a.Barcode })
.IsUnique();
}
}