Aggiunta migrazione x BuyOrder

This commit is contained in:
Samuele Locatelli
2026-04-14 12:25:10 +02:00
parent 0ff38c19a4
commit 2b30e7e8bb
8 changed files with 4524 additions and 22 deletions
+5
View File
@@ -44,8 +44,10 @@
public virtual DbSet<CustomerModel> DbSetCustomer { get; set; }
public virtual DbSet<DealerModel> DbSetDealer { get; set; }
public virtual DbSet<SupplierModel> DbSetSupplier { get; set; }
public virtual DbSet<SupplierQualifyModel> DbSetSupplierQualify { get; set; }
public virtual DbSet<BuyOrderModel> DbSetBuyOrder { get; set; }
public virtual DbSet<BuyOrderRowModel> DbSetBuyOrderRow { get; set; }
public virtual DbSet<OfferModel> DbSetOffer { get; set; }
public virtual DbSet<OfferRowModel> DbSetOfferRow { get; set; }
public virtual DbSet<OrderModel> DbSetOrder { get; set; }
@@ -125,6 +127,9 @@
modelBuilder.Entity<JobStepTagModel>()
.HasKey(jst => new { jst.JobStepID, jst.CodTag });
modelBuilder.Entity<SupplierQualifyModel>()
.HasKey(sq => new { sq.SupplierID, sq.CodGroup });
modelBuilder.Entity<ProductionItem2ODLModel>()
.HasKey(x => new { x.ProdItemID, x.ProdODLID });
@@ -33,5 +33,9 @@
/// </summary>
public string VAT { get; set; } = "";
/// <summary>
/// Many-to-many with Qualifica Fornitori
/// </summary>
public virtual ICollection<SupplierQualifyModel> QualifNav { get; set; } = new List<SupplierQualifyModel>();
}
}
@@ -0,0 +1,15 @@
namespace EgwCoreLib.Lux.Data.DbModel.Supplier
{
[Table("buy_supplier_qualify")]
public class SupplierQualifyModel
{
public int SupplierID { get; set; }
public string CodGroup { get; set; } = "";
[ForeignKey("SupplierID")]
public virtual SupplierModel SupplierNav { get; set; } = null!;
[ForeignKey("CodGroup")]
public virtual ItemGroupModel GroupNav { get; set; } = null!;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,140 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EgwCoreLib.Lux.Data.Migrations
{
/// <inheritdoc />
public partial class UpdateBuyOrderData : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_buy_order_row_sales_order_OrderID",
table: "buy_order_row");
migrationBuilder.DropIndex(
name: "IX_buy_order_row_OrderID",
table: "buy_order_row");
migrationBuilder.RenameColumn(
name: "OrderID",
table: "buy_order_row",
newName: "RowNum");
migrationBuilder.CreateTable(
name: "buy_supplier_qualify",
columns: table => new
{
SupplierID = table.Column<int>(type: "int", nullable: false),
CodGroup = table.Column<string>(type: "varchar(255)", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_buy_supplier_qualify", x => new { x.SupplierID, x.CodGroup });
table.ForeignKey(
name: "FK_buy_supplier_qualify_buy_supplier_SupplierID",
column: x => x.SupplierID,
principalTable: "buy_supplier",
principalColumn: "SupplierID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_buy_supplier_qualify_item_group_CodGroup",
column: x => x.CodGroup,
principalTable: "item_group",
principalColumn: "CodGroup",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 1,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7042));
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 2,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7058));
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 3,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7064));
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 4,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7071));
migrationBuilder.CreateIndex(
name: "IX_buy_supplier_qualify_CodGroup",
table: "buy_supplier_qualify",
column: "CodGroup");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "buy_supplier_qualify");
migrationBuilder.RenameColumn(
name: "RowNum",
table: "buy_order_row",
newName: "OrderID");
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 1,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5680));
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 2,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5692));
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 3,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5699));
migrationBuilder.UpdateData(
table: "sales_offer",
keyColumn: "OfferID",
keyValue: 4,
column: "ValidUntil",
value: new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5705));
migrationBuilder.CreateIndex(
name: "IX_buy_order_row_OrderID",
table: "buy_order_row",
column: "OrderID");
migrationBuilder.AddForeignKey(
name: "FK_buy_order_row_sales_order_OrderID",
table: "buy_order_row",
column: "OrderID",
principalTable: "sales_order",
principalColumn: "OrderID",
onDelete: ReferentialAction.Restrict);
}
}
}
@@ -2219,7 +2219,7 @@ namespace EgwCoreLib.Lux.Data.Migrations
RefNum = 1,
RefRev = 1,
RefYear = 2025,
ValidUntil = new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5680)
ValidUntil = new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7042)
},
new
{
@@ -2239,7 +2239,7 @@ namespace EgwCoreLib.Lux.Data.Migrations
RefNum = 2,
RefRev = 1,
RefYear = 2025,
ValidUntil = new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5692)
ValidUntil = new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7058)
},
new
{
@@ -2259,7 +2259,7 @@ namespace EgwCoreLib.Lux.Data.Migrations
RefNum = 3,
RefRev = 1,
RefYear = 2025,
ValidUntil = new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5699)
ValidUntil = new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7064)
},
new
{
@@ -2279,7 +2279,7 @@ namespace EgwCoreLib.Lux.Data.Migrations
RefNum = 4,
RefRev = 1,
RefYear = 2025,
ValidUntil = new DateTime(2026, 5, 14, 11, 22, 33, 792, DateTimeKind.Local).AddTicks(5705)
ValidUntil = new DateTime(2026, 5, 14, 12, 24, 22, 268, DateTimeKind.Local).AddTicks(7071)
});
});
@@ -3426,21 +3426,19 @@ namespace EgwCoreLib.Lux.Data.Migrations
b.Property<int>("ItemID")
.HasColumnType("int");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<string>("OrderRowData")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("RowNum")
.HasColumnType("int");
b.HasKey("BuyOrderRowID");
b.HasIndex("BuyOrderID");
b.HasIndex("ItemID");
b.HasIndex("OrderID");
b.ToTable("buy_order_row");
});
@@ -3499,6 +3497,21 @@ namespace EgwCoreLib.Lux.Data.Migrations
});
});
modelBuilder.Entity("EgwCoreLib.Lux.Data.DbModel.Supplier.SupplierQualifyModel", b =>
{
b.Property<int>("SupplierID")
.HasColumnType("int");
b.Property<string>("CodGroup")
.HasColumnType("varchar(255)");
b.HasKey("SupplierID", "CodGroup");
b.HasIndex("CodGroup");
b.ToTable("buy_supplier_qualify");
});
modelBuilder.Entity("EgwCoreLib.Lux.Data.DbModel.Utils.CounterModel", b =>
{
b.Property<int>("RefYear")
@@ -4161,17 +4174,28 @@ namespace EgwCoreLib.Lux.Data.Migrations
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("EgwCoreLib.Lux.Data.DbModel.Sales.OrderModel", "OrderNav")
.WithMany()
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("BuyOrderNav");
b.Navigation("ItemNav");
});
b.Navigation("OrderNav");
modelBuilder.Entity("EgwCoreLib.Lux.Data.DbModel.Supplier.SupplierQualifyModel", b =>
{
b.HasOne("EgwCoreLib.Lux.Data.DbModel.Items.ItemGroupModel", "GroupNav")
.WithMany()
.HasForeignKey("CodGroup")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("EgwCoreLib.Lux.Data.DbModel.Supplier.SupplierModel", "SupplierNav")
.WithMany("QualifNav")
.HasForeignKey("SupplierID")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("GroupNav");
b.Navigation("SupplierNav");
});
modelBuilder.Entity("EgwCoreLib.Lux.Data.DbModel.Utils.GenValueModel", b =>
@@ -4242,6 +4266,11 @@ namespace EgwCoreLib.Lux.Data.Migrations
b.Navigation("BuyOrderRowNav");
});
modelBuilder.Entity("EgwCoreLib.Lux.Data.DbModel.Supplier.SupplierModel", b =>
{
b.Navigation("QualifNav");
});
modelBuilder.Entity("EgwCoreLib.Lux.Data.DbModel.Utils.GenClassModel", b =>
{
b.Navigation("GenValNav");
@@ -31,8 +31,14 @@
/// <summary>
/// Recupera gli Supplier filtrati per gruppo e tipo classe.
/// </summary>
/// <param name="CodGroup">Codice del gruppo filtro (vuoto = tutti)</param>
Task<List<SupplierModel>> GetFiltAsync(string CodGroup);
/// <param name="codGroup">Codice del gruppo filtro (vuoto = tutti)</param>
Task<List<SupplierModel>> GetFiltAsync(string codGroup);
/// <summary>
/// Recupera gli Supplier filtrati per più gruppi e tipo classe.
/// </summary>
/// <param name="codGroups">Elenco Codici dei gruppi</param>
Task<List<SupplierModel>> GetFiltAsync(List<string> codGroups);
/// <summary>
/// Aggiorna un record Supplier esistente nel database.
@@ -34,6 +34,7 @@
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetSupplier
.AsNoTracking()
.Include(s => s.QualifNav)
.ToListAsync();
}
@@ -43,17 +44,28 @@
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetSupplier
.Where(x => x.SupplierID == recId)
.Include(s => s.QualifNav)
.FirstOrDefaultAsync();
}
/// <inheritdoc />
public async Task<List<SupplierModel>> GetFiltAsync(string CodGroup)
public async Task<List<SupplierModel>> GetFiltAsync(string codGroup)
{
// FixMet - ToDo: da implementare secondo CodGroup da relazione n-n da implementare
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetSupplier
.AsNoTracking()
.ToListAsync();
.AsNoTracking()
.Include(s => s.QualifNav)
.Where(s => s.QualifNav.Any(q => q.CodGroup == codGroup))
.ToListAsync();
}
public async Task<List<SupplierModel>> GetFiltAsync(List<string> codGroups)
{
await using var dbCtx = await CreateContextAsync();
return await dbCtx.DbSetSupplier
.AsNoTracking()
.Where(s => s.QualifNav.Any(q => codGroups.Contains(q.CodGroup)))
.ToListAsync();
}
/// <inheritdoc />