diff --git a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs index e2122a8..7c45127 100644 --- a/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs +++ b/Data.SeaHavenIndustries/Auth/ApplicationDbContext.cs @@ -42,6 +42,9 @@ namespace Data.SeaHavenIndustries .HasIndex(l => new { l.WorkOrderId, l.SourceWeekStart }) .IsUnique(); + builder.Entity() + .HasIndex(t => new { t.ServiceKey, t.IsActive }); + builder.Entity() .Property(w => w.RowVersion) .IsRowVersion(); @@ -80,6 +83,7 @@ namespace Data.SeaHavenIndustries public DbSet WorkOrderContacts { get; set; } public DbSet workOrderCategories { get; set; } public DbSet workOrderAttachments { get; set; } + public DbSet CompletionDocTemplates { get; set; } public DbSet WorkOrderAuditLogs { get; set; } public DbSet WorkOrderFieldLocks { get; set; } public DbSet WorkOrderWeekRolledLedgers { get; set; } diff --git a/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs b/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs new file mode 100644 index 0000000..08ff98d --- /dev/null +++ b/Data.SeaHavenIndustries/Migrations/20260625120000_Phase6_CompletionSlideOver.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Data.SeaHavenIndustries.Migrations +{ + /// + public partial class Phase6_CompletionSlideOver : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Category", + table: "workOrderAttachments", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "CompletionDocTemplates", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + ServiceKey = table.Column(type: "nvarchar(450)", nullable: false), + WorkOrderType = table.Column(type: "int", nullable: true), + TemplateUrl = table.Column(type: "nvarchar(max)", nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: true), + createdby = table.Column(type: "nvarchar(max)", nullable: true), + DeleterUserId = table.Column(type: "nvarchar(max)", nullable: true), + DeletionTime = table.Column(type: "datetime2", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true), + LastModificationTime = table.Column(type: "datetime2", nullable: true), + LastModifierUserId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CompletionDocTemplates", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_CompletionDocTemplates_ServiceKey_IsActive", + table: "CompletionDocTemplates", + columns: new[] { "ServiceKey", "IsActive" }); + + migrationBuilder.Sql(@" + UPDATE workOrders + SET DocStatus = 1 + WHERE DocStatus IS NULL + AND SignOffAttachment IS NOT NULL + AND LTRIM(RTRIM(SignOffAttachment)) <> ''; + "); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql(@" + UPDATE workOrders + SET DocStatus = NULL + WHERE DocStatus = 1 + AND SignOffAttachment IS NOT NULL + AND LTRIM(RTRIM(SignOffAttachment)) <> ''; + "); + + migrationBuilder.DropTable( + name: "CompletionDocTemplates"); + + migrationBuilder.DropColumn( + name: "Category", + table: "workOrderAttachments"); + } + } +} diff --git a/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs b/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs index c63dda8..2245ad2 100644 --- a/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Data.SeaHavenIndustries/Migrations/ApplicationDbContextModelSnapshot.cs @@ -374,6 +374,61 @@ namespace Data.SeaHavenIndustries.Migrations b.ToTable("Categories", (string)null); }); + modelBuilder.Entity("Data.SeaHavenIndustries.CompletionDocTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleterUserId") + .HasColumnType("nvarchar(max)"); + + b.Property("DeletionTime") + .HasColumnType("datetime2"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModificationTime") + .HasColumnType("datetime2"); + + b.Property("LastModifierUserId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ServiceKey") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("TemplateUrl") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("WorkOrderType") + .HasColumnType("int"); + + b.Property("createdby") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ServiceKey", "IsActive") + .HasDatabaseName("IX_CompletionDocTemplates_ServiceKey_IsActive"); + + b.ToTable("CompletionDocTemplates", (string)null); + }); + modelBuilder.Entity("Data.SeaHavenIndustries.Comments", b => { b.Property("Id") @@ -2064,6 +2119,9 @@ namespace Data.SeaHavenIndustries.Migrations b.Property("Attachments") .HasColumnType("nvarchar(max)"); + b.Property("Category") + .HasColumnType("int"); + b.Property("CreatedDate") .HasColumnType("datetime2"); diff --git a/Data.SeaHavenIndustries/Models/CompletionDocTemplate.cs b/Data.SeaHavenIndustries/Models/CompletionDocTemplate.cs new file mode 100644 index 0000000..17cb4d3 --- /dev/null +++ b/Data.SeaHavenIndustries/Models/CompletionDocTemplate.cs @@ -0,0 +1,13 @@ +using Data.SeaHavenIndustries.Enums; + +namespace Data.SeaHavenIndustries +{ + public class CompletionDocTemplate : FullAuditEntity + { + public string Name { get; set; } = ""; + public string ServiceKey { get; set; } = ""; + public WorkOrderType? WorkOrderType { get; set; } + public string TemplateUrl { get; set; } = ""; + public bool IsActive { get; set; } = true; + } +} diff --git a/Data.SeaHavenIndustries/Models/WorkOrderAttachments.cs b/Data.SeaHavenIndustries/Models/WorkOrderAttachments.cs index ff8672b..fbeee87 100644 --- a/Data.SeaHavenIndustries/Models/WorkOrderAttachments.cs +++ b/Data.SeaHavenIndustries/Models/WorkOrderAttachments.cs @@ -1,15 +1,14 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; -using static System.Runtime.InteropServices.JavaScript.JSType; +using System.ComponentModel.DataAnnotations.Schema; +using Data.SeaHavenIndustries.Enums; namespace Data.SeaHavenIndustries { public class WorkOrderAttachments : FullAuditEntity { public string? Attachments { get; set; } + public WorkOrderMediaCategory? Category { get; set; } public int? WorkorderId { get; set; } [ForeignKey(nameof(WorkorderId))] public virtual WorkOrder? WorkOrder { get; set; } - } }