diff --git a/CutList.Web/Migrations/20260203032915_AddStockItemAndSupplierOffering.Designer.cs b/CutList.Web/Migrations/20260203032915_AddStockItemAndSupplierOffering.Designer.cs new file mode 100644 index 0000000..c1353aa --- /dev/null +++ b/CutList.Web/Migrations/20260203032915_AddStockItemAndSupplierOffering.Designer.cs @@ -0,0 +1,452 @@ +// +using System; +using CutList.Web.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CutList.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260203032915_AddStockItemAndSupplierOffering")] + partial class AddStockItemAndSupplierOffering + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CutList.Web.Data.Entities.CuttingTool", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDefault") + .HasColumnType("bit"); + + b.Property("KerfInches") + .HasPrecision(6, 4) + .HasColumnType("decimal(6,4)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("CuttingTools"); + + b.HasData( + new + { + Id = 1, + IsActive = true, + IsDefault = true, + KerfInches = 0.0625m, + Name = "Bandsaw" + }, + new + { + Id = 2, + IsActive = true, + IsDefault = false, + KerfInches = 0.125m, + Name = "Chop Saw" + }, + new + { + Id = 3, + IsActive = true, + IsDefault = false, + KerfInches = 0.0625m, + Name = "Cold Cut Saw" + }, + new + { + Id = 4, + IsActive = true, + IsDefault = false, + KerfInches = 0.0625m, + Name = "Hacksaw" + }); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Material", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Shape") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Size") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Materials"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.MaterialStockLength", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("LengthInches") + .HasPrecision(10, 4) + .HasColumnType("decimal(10,4)"); + + b.Property("MaterialId") + .HasColumnType("int"); + + b.Property("Notes") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MaterialId", "LengthInches") + .IsUnique(); + + b.ToTable("MaterialStockLengths"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("Customer") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CuttingToolId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Notes") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("CuttingToolId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.ProjectPart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("LengthInches") + .HasPrecision(10, 4) + .HasColumnType("decimal(10,4)"); + + b.Property("MaterialId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ProjectId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("SortOrder") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MaterialId"); + + b.HasIndex("ProjectId"); + + b.ToTable("ProjectParts"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.StockItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("LengthInches") + .HasPrecision(10, 4) + .HasColumnType("decimal(10,4)"); + + b.Property("MaterialId") + .HasColumnType("int"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("MaterialId", "LengthInches") + .IsUnique(); + + b.ToTable("StockItems"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ContactInfo") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Notes") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.SupplierOffering", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Notes") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("PartNumber") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Price") + .HasPrecision(10, 2) + .HasColumnType("decimal(10,2)"); + + b.Property("StockItemId") + .HasColumnType("int"); + + b.Property("SupplierDescription") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("SupplierId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StockItemId"); + + b.HasIndex("SupplierId", "StockItemId") + .IsUnique(); + + b.ToTable("SupplierOfferings"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.MaterialStockLength", b => + { + b.HasOne("CutList.Web.Data.Entities.Material", "Material") + .WithMany("StockLengths") + .HasForeignKey("MaterialId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Material"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Project", b => + { + b.HasOne("CutList.Web.Data.Entities.CuttingTool", "CuttingTool") + .WithMany("Projects") + .HasForeignKey("CuttingToolId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("CuttingTool"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.ProjectPart", b => + { + b.HasOne("CutList.Web.Data.Entities.Material", "Material") + .WithMany("ProjectParts") + .HasForeignKey("MaterialId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("CutList.Web.Data.Entities.Project", "Project") + .WithMany("Parts") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Material"); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.StockItem", b => + { + b.HasOne("CutList.Web.Data.Entities.Material", "Material") + .WithMany("StockItems") + .HasForeignKey("MaterialId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Material"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.SupplierOffering", b => + { + b.HasOne("CutList.Web.Data.Entities.StockItem", "StockItem") + .WithMany("SupplierOfferings") + .HasForeignKey("StockItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CutList.Web.Data.Entities.Supplier", "Supplier") + .WithMany("Offerings") + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StockItem"); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.CuttingTool", b => + { + b.Navigation("Projects"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Material", b => + { + b.Navigation("ProjectParts"); + + b.Navigation("StockItems"); + + b.Navigation("StockLengths"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Project", b => + { + b.Navigation("Parts"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.StockItem", b => + { + b.Navigation("SupplierOfferings"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b => + { + b.Navigation("Offerings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CutList.Web/Migrations/20260203032915_AddStockItemAndSupplierOffering.cs b/CutList.Web/Migrations/20260203032915_AddStockItemAndSupplierOffering.cs new file mode 100644 index 0000000..8db9ca1 --- /dev/null +++ b/CutList.Web/Migrations/20260203032915_AddStockItemAndSupplierOffering.cs @@ -0,0 +1,141 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CutList.Web.Migrations +{ + /// + public partial class AddStockItemAndSupplierOffering : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "SupplierStocks"); + + migrationBuilder.CreateTable( + name: "StockItems", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + MaterialId = table.Column(type: "int", nullable: false), + LengthInches = table.Column(type: "decimal(10,4)", precision: 10, scale: 4, nullable: false), + Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), + IsActive = table.Column(type: "bit", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), + UpdatedAt = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_StockItems", x => x.Id); + table.ForeignKey( + name: "FK_StockItems_Materials_MaterialId", + column: x => x.MaterialId, + principalTable: "Materials", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SupplierOfferings", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + StockItemId = table.Column(type: "int", nullable: false), + SupplierId = table.Column(type: "int", nullable: false), + PartNumber = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), + SupplierDescription = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + Price = table.Column(type: "decimal(10,2)", precision: 10, scale: 2, nullable: true), + Notes = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + IsActive = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SupplierOfferings", x => x.Id); + table.ForeignKey( + name: "FK_SupplierOfferings_StockItems_StockItemId", + column: x => x.StockItemId, + principalTable: "StockItems", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SupplierOfferings_Suppliers_SupplierId", + column: x => x.SupplierId, + principalTable: "Suppliers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_StockItems_MaterialId_LengthInches", + table: "StockItems", + columns: new[] { "MaterialId", "LengthInches" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_SupplierOfferings_StockItemId", + table: "SupplierOfferings", + column: "StockItemId"); + + migrationBuilder.CreateIndex( + name: "IX_SupplierOfferings_SupplierId_StockItemId", + table: "SupplierOfferings", + columns: new[] { "SupplierId", "StockItemId" }, + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "SupplierOfferings"); + + migrationBuilder.DropTable( + name: "StockItems"); + + migrationBuilder.CreateTable( + name: "SupplierStocks", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + MaterialId = table.Column(type: "int", nullable: false), + SupplierId = table.Column(type: "int", nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + LengthInches = table.Column(type: "decimal(10,4)", precision: 10, scale: 4, nullable: false), + Notes = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + Price = table.Column(type: "decimal(10,2)", precision: 10, scale: 2, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_SupplierStocks", x => x.Id); + table.ForeignKey( + name: "FK_SupplierStocks_Materials_MaterialId", + column: x => x.MaterialId, + principalTable: "Materials", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SupplierStocks_Suppliers_SupplierId", + column: x => x.SupplierId, + principalTable: "Suppliers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_SupplierStocks_MaterialId", + table: "SupplierStocks", + column: "MaterialId"); + + migrationBuilder.CreateIndex( + name: "IX_SupplierStocks_SupplierId_MaterialId_LengthInches", + table: "SupplierStocks", + columns: new[] { "SupplierId", "MaterialId", "LengthInches" }, + unique: true); + } + } +} diff --git a/CutList.Web/Migrations/ApplicationDbContextModelSnapshot.cs b/CutList.Web/Migrations/ApplicationDbContextModelSnapshot.cs index 6caf264..93115b3 100644 --- a/CutList.Web/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/CutList.Web/Migrations/ApplicationDbContextModelSnapshot.cs @@ -231,6 +231,44 @@ namespace CutList.Web.Migrations b.ToTable("ProjectParts"); }); + modelBuilder.Entity("CutList.Web.Data.Entities.StockItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValueSql("GETUTCDATE()"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("LengthInches") + .HasPrecision(10, 4) + .HasColumnType("decimal(10,4)"); + + b.Property("MaterialId") + .HasColumnType("int"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("MaterialId", "LengthInches") + .IsUnique(); + + b.ToTable("StockItems"); + }); + modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b => { b.Property("Id") @@ -264,7 +302,7 @@ namespace CutList.Web.Migrations b.ToTable("Suppliers"); }); - modelBuilder.Entity("CutList.Web.Data.Entities.SupplierStock", b => + modelBuilder.Entity("CutList.Web.Data.Entities.SupplierOffering", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -275,32 +313,36 @@ namespace CutList.Web.Migrations b.Property("IsActive") .HasColumnType("bit"); - b.Property("LengthInches") - .HasPrecision(10, 4) - .HasColumnType("decimal(10,4)"); - - b.Property("MaterialId") - .HasColumnType("int"); - b.Property("Notes") .HasMaxLength(255) .HasColumnType("nvarchar(255)"); + b.Property("PartNumber") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + b.Property("Price") .HasPrecision(10, 2) .HasColumnType("decimal(10,2)"); + b.Property("StockItemId") + .HasColumnType("int"); + + b.Property("SupplierDescription") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + b.Property("SupplierId") .HasColumnType("int"); b.HasKey("Id"); - b.HasIndex("MaterialId"); + b.HasIndex("StockItemId"); - b.HasIndex("SupplierId", "MaterialId", "LengthInches") + b.HasIndex("SupplierId", "StockItemId") .IsUnique(); - b.ToTable("SupplierStocks"); + b.ToTable("SupplierOfferings"); }); modelBuilder.Entity("CutList.Web.Data.Entities.MaterialStockLength", b => @@ -343,21 +385,32 @@ namespace CutList.Web.Migrations b.Navigation("Project"); }); - modelBuilder.Entity("CutList.Web.Data.Entities.SupplierStock", b => + modelBuilder.Entity("CutList.Web.Data.Entities.StockItem", b => { b.HasOne("CutList.Web.Data.Entities.Material", "Material") - .WithMany("SupplierStocks") + .WithMany("StockItems") .HasForeignKey("MaterialId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Material"); + }); + + modelBuilder.Entity("CutList.Web.Data.Entities.SupplierOffering", b => + { + b.HasOne("CutList.Web.Data.Entities.StockItem", "StockItem") + .WithMany("SupplierOfferings") + .HasForeignKey("StockItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("CutList.Web.Data.Entities.Supplier", "Supplier") - .WithMany("Stocks") + .WithMany("Offerings") .HasForeignKey("SupplierId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Material"); + b.Navigation("StockItem"); b.Navigation("Supplier"); }); @@ -371,9 +424,9 @@ namespace CutList.Web.Migrations { b.Navigation("ProjectParts"); - b.Navigation("StockLengths"); + b.Navigation("StockItems"); - b.Navigation("SupplierStocks"); + b.Navigation("StockLengths"); }); modelBuilder.Entity("CutList.Web.Data.Entities.Project", b => @@ -381,9 +434,14 @@ namespace CutList.Web.Migrations b.Navigation("Parts"); }); + modelBuilder.Entity("CutList.Web.Data.Entities.StockItem", b => + { + b.Navigation("SupplierOfferings"); + }); + modelBuilder.Entity("CutList.Web.Data.Entities.Supplier", b => { - b.Navigation("Stocks"); + b.Navigation("Offerings"); }); #pragma warning restore 612, 618 }