Browse Source

remove AttachmentType from contract

zinab_elgendy 1 day ago
parent
commit
a1ba1df818

+ 35 - 0
MTWorkHR.API/Controllers/AttachmentController.cs

@@ -0,0 +1,35 @@
+using Microsoft.AspNetCore.Authorization;
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using MTWorkHR.Application.Filters;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Application.Services;
+using MTWorkHR.Application.Services.Interfaces;
+
+namespace MTWorkHR.API.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    [AppAuthorize]
+    public class AttachmentController : ControllerBase
+    {
+        private readonly IFileService _fileService;
+
+        public AttachmentController(IFileService fileService)
+        {
+            _fileService = fileService;
+        }
+        
+
+        [HttpPost("Upload")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        [Consumes("multipart/form-data")]
+        public async Task<ActionResult<string>> Upload(IFormFile input)
+        {
+            return await _fileService.UploadFile(input);
+        }
+
+
+    }
+}

+ 1 - 1
MTWorkHR.API/Program.cs

@@ -38,7 +38,7 @@ var config = new AppSettingsConfiguration();
 // Add services to the container.
 builder.Services.AddDbContext<HRDataContext>(options =>
 {
-    options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
+    options.UseSqlServer(config.ConnectionStrings.MTWorkHRConnectionString);
     //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });
 

+ 2 - 5
MTWorkHR.Application/Dtos/Contract/ContractTaskAttachmentDto.cs

@@ -8,20 +8,17 @@ namespace MTWorkHR.Application.Models
 {
     public class ContractTaskAttachmentDto : EntityDto
     {
-        public long ContractTaskId { get; set; }
+        public long ContractTaskId { get; set; } = 0;
 
         public long? AttachmentTypeId { get; set; }
 
-        [ForeignKey("AttachmentTypeId")]
-        public AttachmentType AttachmentType { get; set; }
-
+     
         [MaxLength(250)]
         public string? FileName { get; set; }
 
         [MaxLength(250)]
         public string? OriginalName { get; set; }
         public IFormFile? FileData { get; set; }
-        public byte[] Content { get; set; }
         public string? FilePath { get; set; }
         public string? ContentType { get; set; }
     }

+ 1 - 4
MTWorkHR.Application/Dtos/Contract/ProjectStageAttachmentDto.cs

@@ -8,12 +8,10 @@ namespace MTWorkHR.Application.Models
 {
     public class ProjectStageAttachmentDto : EntityDto
     {
-        public long ProjectStageId { get; set; }
+        public long ProjectStageId { get; set; } = 0;
 
         public long? AttachmentTypeId { get; set; }
 
-        [ForeignKey("AttachmentTypeId")]
-        public AttachmentType AttachmentType { get; set; }
 
         [MaxLength(250)]
         public string? FileName { get; set; }
@@ -22,7 +20,6 @@ namespace MTWorkHR.Application.Models
         public string? OriginalName { get; set; }
         public IFormFile? FileData { get; set; }
 
-        public byte[] Content { get; set; }
         public string? FilePath { get; set; }
         public string? ContentType { get; set; }
     }

+ 1 - 3
MTWorkHR.Core/Entities/Contract/ContractTaskAttachment.cs

@@ -13,8 +13,7 @@ namespace MTWorkHR.Core.Entities
         public ContractTask ContractTask { get; set; }
         public long? AttachmentTypeId { get; set; }
 
-        [ForeignKey("AttachmentTypeId")]
-        public AttachmentType AttachmentType { get; set; }
+       
 
         [MaxLength(250)]
         public string? FileName { get; set; }
@@ -22,7 +21,6 @@ namespace MTWorkHR.Core.Entities
         [MaxLength(250)]
         public string? OriginalName { get; set; }
 
-        public byte[] Content { get; set; }
         public string? FilePath { get; set; }
         public string? ContentType { get; set; }
     }

+ 0 - 3
MTWorkHR.Core/Entities/Contract/ProjectStageAttachment.cs

@@ -13,8 +13,6 @@ namespace MTWorkHR.Core.Entities
         public ProjectStage ProjectStage { get; set; }
         public long? AttachmentTypeId { get; set; }
 
-        [ForeignKey("AttachmentTypeId")]
-        public AttachmentType AttachmentType { get; set; }
 
         [MaxLength(250)]
         public string? FileName { get; set; }
@@ -22,7 +20,6 @@ namespace MTWorkHR.Core.Entities
         [MaxLength(250)]
         public string? OriginalName { get; set; }
 
-        public byte[] Content { get; set; }
         public string? FilePath { get; set; }
         public string? ContentType { get; set; }
     }

+ 1 - 1
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -32,7 +32,7 @@ namespace MTWorkHR.Infrastructure
             
             services.AddDbContext<HRDataContext>(options =>
                 options.UseSqlServer(
-                    config.ConnectionStrings.LocalConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
+                    config.ConnectionStrings.MTWorkHRConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
                     ));
            
             services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();

File diff suppressed because it is too large
+ 5749 - 0
MTWorkHR.Infrastructure/Migrations/20241224101338_altrContracyAttachs.Designer.cs


+ 80 - 0
MTWorkHR.Infrastructure/Migrations/20241224101338_altrContracyAttachs.cs

@@ -0,0 +1,80 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrContracyAttachs : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_ContractTaskAttachment_AttachmentTypes_AttachmentTypeId",
+                table: "ContractTaskAttachment");
+
+            migrationBuilder.DropForeignKey(
+                name: "FK_ProjectStageAttachment_AttachmentTypes_AttachmentTypeId",
+                table: "ProjectStageAttachment");
+
+            migrationBuilder.DropIndex(
+                name: "IX_ProjectStageAttachment_AttachmentTypeId",
+                table: "ProjectStageAttachment");
+
+            migrationBuilder.DropIndex(
+                name: "IX_ContractTaskAttachment_AttachmentTypeId",
+                table: "ContractTaskAttachment");
+
+            migrationBuilder.DropColumn(
+                name: "Content",
+                table: "ProjectStageAttachment");
+
+            migrationBuilder.DropColumn(
+                name: "Content",
+                table: "ContractTaskAttachment");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AddColumn<byte[]>(
+                name: "Content",
+                table: "ProjectStageAttachment",
+                type: "varbinary(max)",
+                nullable: false,
+                defaultValue: new byte[0]);
+
+            migrationBuilder.AddColumn<byte[]>(
+                name: "Content",
+                table: "ContractTaskAttachment",
+                type: "varbinary(max)",
+                nullable: false,
+                defaultValue: new byte[0]);
+
+            migrationBuilder.CreateIndex(
+                name: "IX_ProjectStageAttachment_AttachmentTypeId",
+                table: "ProjectStageAttachment",
+                column: "AttachmentTypeId");
+
+            migrationBuilder.CreateIndex(
+                name: "IX_ContractTaskAttachment_AttachmentTypeId",
+                table: "ContractTaskAttachment",
+                column: "AttachmentTypeId");
+
+            migrationBuilder.AddForeignKey(
+                name: "FK_ContractTaskAttachment_AttachmentTypes_AttachmentTypeId",
+                table: "ContractTaskAttachment",
+                column: "AttachmentTypeId",
+                principalTable: "AttachmentTypes",
+                principalColumn: "Id");
+
+            migrationBuilder.AddForeignKey(
+                name: "FK_ProjectStageAttachment_AttachmentTypes_AttachmentTypeId",
+                table: "ProjectStageAttachment",
+                column: "AttachmentTypeId",
+                principalTable: "AttachmentTypes",
+                principalColumn: "Id");
+        }
+    }
+}

+ 0 - 24
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -812,10 +812,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<long?>("AttachmentTypeId")
                         .HasColumnType("bigint");
 
-                    b.Property<byte[]>("Content")
-                        .IsRequired()
-                        .HasColumnType("varbinary(max)");
-
                     b.Property<string>("ContentType")
                         .HasColumnType("nvarchar(max)");
 
@@ -853,8 +849,6 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.HasIndex("AttachmentTypeId");
-
                     b.HasIndex("ContractTaskId");
 
                     b.ToTable("ContractTaskAttachment");
@@ -3768,10 +3762,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<long?>("AttachmentTypeId")
                         .HasColumnType("bigint");
 
-                    b.Property<byte[]>("Content")
-                        .IsRequired()
-                        .HasColumnType("varbinary(max)");
-
                     b.Property<string>("ContentType")
                         .HasColumnType("nvarchar(max)");
 
@@ -3809,8 +3799,6 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.HasIndex("AttachmentTypeId");
-
                     b.HasIndex("ProjectStageId");
 
                     b.ToTable("ProjectStageAttachment");
@@ -5358,18 +5346,12 @@ namespace MTWorkHR.Infrastructure.Migrations
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractTaskAttachment", b =>
                 {
-                    b.HasOne("MTWorkHR.Core.Entities.Base.AttachmentType", "AttachmentType")
-                        .WithMany()
-                        .HasForeignKey("AttachmentTypeId");
-
                     b.HasOne("MTWorkHR.Core.Entities.ContractTask", "ContractTask")
                         .WithMany("TaskAttachments")
                         .HasForeignKey("ContractTaskId")
                         .OnDelete(DeleteBehavior.Cascade)
                         .IsRequired();
 
-                    b.Navigation("AttachmentType");
-
                     b.Navigation("ContractTask");
                 });
 
@@ -5425,18 +5407,12 @@ namespace MTWorkHR.Infrastructure.Migrations
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectStageAttachment", b =>
                 {
-                    b.HasOne("MTWorkHR.Core.Entities.Base.AttachmentType", "AttachmentType")
-                        .WithMany()
-                        .HasForeignKey("AttachmentTypeId");
-
                     b.HasOne("MTWorkHR.Core.Entities.ProjectStage", "ProjectStage")
                         .WithMany("StageAttachments")
                         .HasForeignKey("ProjectStageId")
                         .OnDelete(DeleteBehavior.Cascade)
                         .IsRequired();
 
-                    b.Navigation("AttachmentType");
-
                     b.Navigation("ProjectStage");
                 });