zinab_elgendy 5 meses atrás
pai
commit
015b0ffa95

+ 1 - 1
MTWorkHR.Application/ApplicationServiceRegistration.cs

@@ -22,7 +22,7 @@ namespace MTWorkHR.Application
 
             services.AddTransient<IAuthService, AuthService>();
             services.AddTransient<IUserService, UserService>();
-           // services.AddTransient<IFileService, FileService>();
+            //services.AddTransient<IFileService, FileService>();
             services.AddTransient<IFileService, BlobFileService>();
             services.AddScoped<IProjectService, ProjectService>();
             services.AddScoped<IUserTaskService, UserTaskService>();

+ 1 - 1
MTWorkHR.Application/Dtos/User/UserTaskDto.cs

@@ -15,7 +15,7 @@ namespace MTWorkHR.Application.Models
 
         public long StatusId { get; set; }
         public List<AttachmentDto> TaskAttachments { get; set; }
-        public List<UserTaskHistoryDto> UserTaskHistories { get; set; }
+        public List<UserTaskHistoryDto> TaskHistories { get; set; }
         public string? CreateUser { get; set; }
 
     }

+ 1 - 1
MTWorkHR.Application/Dtos/User/UserTaskHistoryDto.cs

@@ -13,7 +13,7 @@ namespace MTWorkHR.Application.Models
         [MaxLength(500)]
         public string? Comment { get; set; }
 
-        public long UserTaskId { get; set; }
+        public long TaskId { get; set; }
 
         public long CurrentStatusId { get; set; }
 

+ 1 - 1
MTWorkHR.Application/Mapper/MappingProfile.cs

@@ -82,7 +82,7 @@ namespace MTWorkHR.Application.Mapper
 
             CreateMap<UserTask, UserTaskAllDto>()
             .ForMember(s => s.AttachmentCount, o => o.MapFrom(s => s.TaskAttachments == null ? 0 : s.TaskAttachments.Count))
-            .ForMember(s => s.CommentsCount, o => o.MapFrom(s => s.UserTaskHistories== null ? 0 : s.UserTaskHistories.Count));
+            .ForMember(s => s.CommentsCount, o => o.MapFrom(s => s.TaskHistories== null ? 0 : s.TaskHistories.Count));
 
 
             CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());

+ 1 - 1
MTWorkHR.Core/Entities/User/UserTask.cs

@@ -27,7 +27,7 @@ namespace MTWorkHR.Core.Entities
         [ForeignKey("StatusId")]
         public UserTaskStatus TaskStatus { get; set; }
         public List<UserTaskAttachment> TaskAttachments { get; set; }
-        public List<UserTaskHistory> UserTaskHistories { get; set; }
+        public List<UserTaskHistory> TaskHistories { get; set; }
         public long CompanyId { get ; set ; }
     }
 }

+ 2 - 0
MTWorkHR.Core/Entities/User/UserTaskHistory.cs

@@ -18,6 +18,8 @@ namespace MTWorkHR.Core.Entities
         public string? Comment { get; set; }
         public long TaskId { get; set; }
 
+        [ForeignKey("TaskId ")]
+        public UserTask UserTask { get; set; }
         public long CurrentStatusId { get; set; }
 
         [ForeignKey("CurrentStatusId")]

Diferenças do arquivo suprimidas por serem muito extensas
+ 3419 - 0
MTWorkHR.Infrastructure/Migrations/20240730144541_altrTaskHistory2.Designer.cs


+ 69 - 0
MTWorkHR.Infrastructure/Migrations/20240730144541_altrTaskHistory2.cs

@@ -0,0 +1,69 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrTaskHistory2 : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_UserTaskHistories_UserTasks_UserTaskId",
+                table: "UserTaskHistories");
+
+            migrationBuilder.DropIndex(
+                name: "IX_UserTaskHistories_UserTaskId",
+                table: "UserTaskHistories");
+
+            migrationBuilder.DropColumn(
+                name: "UserTaskId",
+                table: "UserTaskHistories");
+
+            migrationBuilder.CreateIndex(
+                name: "IX_UserTaskHistories_TaskId",
+                table: "UserTaskHistories",
+                column: "TaskId");
+
+            migrationBuilder.AddForeignKey(
+                name: "FK_UserTaskHistories_UserTasks_TaskId",
+                table: "UserTaskHistories",
+                column: "TaskId",
+                principalTable: "UserTasks",
+                principalColumn: "Id",
+                onDelete: ReferentialAction.NoAction);
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_UserTaskHistories_UserTasks_TaskId",
+                table: "UserTaskHistories");
+
+            migrationBuilder.DropIndex(
+                name: "IX_UserTaskHistories_TaskId",
+                table: "UserTaskHistories");
+
+            migrationBuilder.AddColumn<long>(
+                name: "UserTaskId",
+                table: "UserTaskHistories",
+                type: "bigint",
+                nullable: true);
+
+            migrationBuilder.CreateIndex(
+                name: "IX_UserTaskHistories_UserTaskId",
+                table: "UserTaskHistories",
+                column: "UserTaskId");
+
+            migrationBuilder.AddForeignKey(
+                name: "FK_UserTaskHistories_UserTasks_UserTaskId",
+                table: "UserTaskHistories",
+                column: "UserTaskId",
+                principalTable: "UserTasks",
+                principalColumn: "Id");
+        }
+    }
+}

+ 9 - 8
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -2413,14 +2413,11 @@ namespace MTWorkHR.Infrastructure.Migrations
                         .HasColumnType("nvarchar(450)")
                         .HasColumnOrder(2);
 
-                    b.Property<long?>("UserTaskId")
-                        .HasColumnType("bigint");
-
                     b.HasKey("Id");
 
                     b.HasIndex("CurrentStatusId");
 
-                    b.HasIndex("UserTaskId");
+                    b.HasIndex("TaskId");
 
                     b.ToTable("UserTaskHistories");
                 });
@@ -3217,11 +3214,15 @@ namespace MTWorkHR.Infrastructure.Migrations
                         .OnDelete(DeleteBehavior.Cascade)
                         .IsRequired();
 
-                    b.HasOne("MTWorkHR.Core.Entities.UserTask", null)
-                        .WithMany("UserTaskHistories")
-                        .HasForeignKey("UserTaskId");
+                    b.HasOne("MTWorkHR.Core.Entities.UserTask", "UserTask")
+                        .WithMany("TaskHistories")
+                        .HasForeignKey("TaskId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
 
                     b.Navigation("TaskStatus");
+
+                    b.Navigation("UserTask");
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.ApplicationUser", b =>
@@ -3394,7 +3395,7 @@ namespace MTWorkHR.Infrastructure.Migrations
                 {
                     b.Navigation("TaskAttachments");
 
-                    b.Navigation("UserTaskHistories");
+                    b.Navigation("TaskHistories");
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.ApplicationRole", b =>

+ 3 - 3
MTWorkHR.Infrastructure/Repositories/Task/UserTaskRepository.cs

@@ -20,7 +20,7 @@ namespace MTWorkHR.Infrastructure.Repositories
         {
             return await dbSet
                 .Include(x => x.TaskAttachments).ThenInclude(a => a.AttachmentType)
-                .Include(x => x.UserTaskHistories)
+                .Include(x => x.TaskHistories)
                 .Include(x => x.TaskStatus)
                 .Include(x => x.Project)
                 .FirstOrDefaultAsync(x => x.Id == id);
@@ -31,7 +31,7 @@ namespace MTWorkHR.Infrastructure.Repositories
         {
             return await dbSet
                 .Include(x => x.TaskAttachments).ThenInclude(a => a.AttachmentType)
-                .Include(x => x.UserTaskHistories)
+                .Include(x => x.TaskHistories)
                 .Include(x => x.TaskStatus)
                 .Include(x => x.Project)
                 .FirstOrDefaultAsync(x => x.AssignedUserId == userId);
@@ -40,7 +40,7 @@ namespace MTWorkHR.Infrastructure.Repositories
         public async Task<Tuple<IQueryable<UserTask>, int>> GetAllWithChildrenAsync()
         {
             var query = dbSet.Include(x => x.Project).Include(x => x.TaskAttachments)
-                .Include(x => x.UserTaskHistories).AsQueryable();
+                .Include(x => x.TaskHistories).AsQueryable();
             var total = await query.CountAsync();
 
             return new Tuple<IQueryable<UserTask>, int>(query, total);