Add PurchaseItem entity with status tracking (Pending/Ordered/Received), supplier and job relationships. Add LockedAt timestamp to Job entity for controlling editability after materials are ordered. Includes PurchaseItemService (CRUD + bulk create), JobService Lock/Unlock methods, EF Core migrations, and DI registration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
76 lines
3.1 KiB
C#
76 lines
3.1 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace CutList.Web.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddPurchaseItem : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "PurchaseItems",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
StockItemId = table.Column<int>(type: "int", nullable: false),
|
|
SupplierId = table.Column<int>(type: "int", nullable: true),
|
|
Quantity = table.Column<int>(type: "int", nullable: false),
|
|
JobId = table.Column<int>(type: "int", nullable: true),
|
|
Notes = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
|
Status = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
|
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_PurchaseItems", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_PurchaseItems_Jobs_JobId",
|
|
column: x => x.JobId,
|
|
principalTable: "Jobs",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_PurchaseItems_StockItems_StockItemId",
|
|
column: x => x.StockItemId,
|
|
principalTable: "StockItems",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_PurchaseItems_Suppliers_SupplierId",
|
|
column: x => x.SupplierId,
|
|
principalTable: "Suppliers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PurchaseItems_JobId",
|
|
table: "PurchaseItems",
|
|
column: "JobId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PurchaseItems_StockItemId",
|
|
table: "PurchaseItems",
|
|
column: "StockItemId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_PurchaseItems_SupplierId",
|
|
table: "PurchaseItems",
|
|
column: "SupplierId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "PurchaseItems");
|
|
}
|
|
}
|
|
}
|