refactor: Replace SupplierStock with StockItem/SupplierOffering model
- Remove SupplierStock entity - Update Material navigation from SupplierStocks to StockItems - Update Supplier navigation from Stocks to Offerings - Update ApplicationDbContext with new DbSets and configurations - Add unique constraints: StockItem(MaterialId, LengthInches) and SupplierOffering(SupplierId, StockItemId) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,8 @@ public class ApplicationDbContext : DbContext
|
||||
public DbSet<Material> Materials => Set<Material>();
|
||||
public DbSet<MaterialStockLength> MaterialStockLengths => Set<MaterialStockLength>();
|
||||
public DbSet<Supplier> Suppliers => Set<Supplier>();
|
||||
public DbSet<SupplierStock> SupplierStocks => Set<SupplierStock>();
|
||||
public DbSet<StockItem> StockItems => Set<StockItem>();
|
||||
public DbSet<SupplierOffering> SupplierOfferings => Set<SupplierOffering>();
|
||||
public DbSet<CuttingTool> CuttingTools => Set<CuttingTool>();
|
||||
public DbSet<Project> Projects => Set<Project>();
|
||||
public DbSet<ProjectPart> ProjectParts => Set<ProjectPart>();
|
||||
@@ -56,25 +57,42 @@ public class ApplicationDbContext : DbContext
|
||||
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
|
||||
});
|
||||
|
||||
// SupplierStock
|
||||
modelBuilder.Entity<SupplierStock>(entity =>
|
||||
// StockItem
|
||||
modelBuilder.Entity<StockItem>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.LengthInches).HasPrecision(10, 4);
|
||||
entity.Property(e => e.Price).HasPrecision(10, 2);
|
||||
entity.Property(e => e.Notes).HasMaxLength(255);
|
||||
|
||||
entity.HasOne(e => e.Supplier)
|
||||
.WithMany(s => s.Stocks)
|
||||
.HasForeignKey(e => e.SupplierId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
entity.Property(e => e.Name).HasMaxLength(100);
|
||||
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
|
||||
|
||||
entity.HasOne(e => e.Material)
|
||||
.WithMany(m => m.SupplierStocks)
|
||||
.WithMany(m => m.StockItems)
|
||||
.HasForeignKey(e => e.MaterialId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasIndex(e => new { e.SupplierId, e.MaterialId, e.LengthInches }).IsUnique();
|
||||
entity.HasIndex(e => new { e.MaterialId, e.LengthInches }).IsUnique();
|
||||
});
|
||||
|
||||
// SupplierOffering
|
||||
modelBuilder.Entity<SupplierOffering>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.PartNumber).HasMaxLength(100);
|
||||
entity.Property(e => e.SupplierDescription).HasMaxLength(255);
|
||||
entity.Property(e => e.Price).HasPrecision(10, 2);
|
||||
entity.Property(e => e.Notes).HasMaxLength(255);
|
||||
|
||||
entity.HasOne(e => e.StockItem)
|
||||
.WithMany(s => s.SupplierOfferings)
|
||||
.HasForeignKey(e => e.StockItemId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasOne(e => e.Supplier)
|
||||
.WithMany(s => s.Offerings)
|
||||
.HasForeignKey(e => e.SupplierId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasIndex(e => new { e.SupplierId, e.StockItemId }).IsUnique();
|
||||
});
|
||||
|
||||
// CuttingTool
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Material
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
|
||||
public ICollection<SupplierStock> SupplierStocks { get; set; } = new List<SupplierStock>();
|
||||
public ICollection<StockItem> StockItems { get; set; } = new List<StockItem>();
|
||||
public ICollection<MaterialStockLength> StockLengths { get; set; } = new List<MaterialStockLength>();
|
||||
public ICollection<ProjectPart> ProjectParts { get; set; } = new List<ProjectPart>();
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ public class Supplier
|
||||
public bool IsActive { get; set; } = true;
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public ICollection<SupplierStock> Stocks { get; set; } = new List<SupplierStock>();
|
||||
public ICollection<SupplierOffering> Offerings { get; set; } = new List<SupplierOffering>();
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace CutList.Web.Data.Entities;
|
||||
|
||||
public class SupplierStock
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
public int MaterialId { get; set; }
|
||||
public decimal LengthInches { get; set; }
|
||||
public decimal? Price { get; set; }
|
||||
public string? Notes { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public Supplier Supplier { get; set; } = null!;
|
||||
public Material Material { get; set; } = null!;
|
||||
}
|
||||
Reference in New Issue
Block a user