Browse Source

AssignTeamAdminManager

zinab_elgendy 11 months ago
parent
commit
0a75f74640

+ 8 - 0
MTWorkHR.API/Controllers/TeamController.cs

@@ -57,6 +57,14 @@ namespace MTWorkHR.API.Controllers
             await _TeamService.Delete(id);
         }
 
+        [HttpPost("AssignAdminManager")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<bool> AssignAdminManager([FromBody] TeamUserDto teamUser)
+        {
+            return await _TeamService.AssignAdminManager(teamUser);
+        }
+
 
 
     }

+ 4 - 1
MTWorkHR.Application/Dtos/User/MeetingDto.cs

@@ -16,7 +16,10 @@ namespace MTWorkHR.Application.Models
         [MaxLength(500)]
         [Filter]
         public string? Description { get; set; }
-        public DateTime MeetingDateTime { get; set; }
+        public DateTime StartDate { get; set; }
+        public DateTime EndDate { get; set; }
+        [MaxLength(250)]
+        public string? Location { get; set; }
         [MaxLength(250)]
         public string? MeetingLink { get; set; }
         public List<MeetingUserDto>? MeetingUsers { get; set; }

+ 1 - 0
MTWorkHR.Application/Dtos/User/TeamUserDto.cs

@@ -9,6 +9,7 @@ namespace MTWorkHR.Application.Models
     public class TeamUserDto : EntityDto
     {
         public long TeamId { get; set; }
+        public bool IsAdmin{ get; set; }
         [Required]
         public string AssignedUserId { get; set; }
         public string? AssignedUserName { get; set; }

+ 9 - 8
MTWorkHR.Application/Mapper/MappingProfile.cs

@@ -58,16 +58,17 @@ namespace MTWorkHR.Application.Mapper
 
             CreateMap<RolePermissionDto, RolePermission>().ReverseMap();
 
-            CreateMap<ProjectDto, Project>().ReverseMap();
-            CreateMap<UserTaskDto, UserTask>().ReverseMap();
+            CreateMap<ProjectDto, Project>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
+            CreateMap<UserTaskDto, UserTask>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
             CreateMap<UserTaskAttachment, AttachmentDto>().ReverseMap();
-            CreateMap<UserTaskHistory, UserTaskHistoryDto>().ReverseMap();
-            CreateMap<Team, TeamDto>().ReverseMap();
-            CreateMap<TeamUser, TeamUserDto>().ReverseMap();
-            CreateMap<Meeting, MeetingDto>().ReverseMap();
-            CreateMap<MeetingUser, MeetingUserDto>().ReverseMap();
+            CreateMap<UserTaskHistoryDto, UserTaskHistory>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
+            CreateMap<Team, TeamDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
+            CreateMap<TeamUserDto, TeamUser>().ForMember(d => d.CreateDate, o => o.Ignore()).ReverseMap();
+            CreateMap<Meeting, MeetingDto>().ReverseMap()
+                .ForMember(d => d.CreateDate, o => o.Ignore());
+            CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
+
 
-            
 
         }
     }

+ 1 - 0
MTWorkHR.Application/Services/Interfaces/ITeamService.cs

@@ -7,5 +7,6 @@ namespace MTWorkHR.Application.Services.Interfaces
 {
     public interface ITeamService : IService<Team, TeamDto, TeamDto>
     {
+        Task<bool> AssignAdminManager(TeamUserDto teamUser);
     }
 }

+ 28 - 15
MTWorkHR.Application/Services/User/TeamService.cs

@@ -19,9 +19,7 @@ namespace MTWorkHR.Application.Services
     public class TeamService : BaseService<Team, TeamDto, TeamDto>, ITeamService
     {
         private readonly IUnitOfWork _unitOfWork;
-        //private readonly AppSettingsConfiguration _configuration;
-        //private readonly GlobalInfo _globalInfo;
-
+      
         public TeamService(IUnitOfWork unitOfWork):base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
@@ -34,19 +32,34 @@ namespace MTWorkHR.Application.Services
             var response = MapperObject.Mapper.Map<TeamDto>(entity);
             return response;
         }
+       
+        public async Task<bool> AssignAdminManager(TeamUserDto teamUser)
+        {
+            var result = false;
+            var team = await _unitOfWork.Team.GetByIdWithAllChildren(teamUser.TeamId);
+            if (team?.TeamUsers != null)
+            {
+                var foundUser = team.TeamUsers.FirstOrDefault(u => u.AssignedUserId == teamUser.AssignedUserId);
+                if (foundUser != null)
+                {
+                    foundUser.IsAdmin = teamUser.IsAdmin;
+                }
+                else
+                {
+                    team.TeamUsers.Add(new TeamUser { IsAdmin = teamUser.IsAdmin, AssignedUserId = teamUser.AssignedUserId});
+                }
+            }
+            else if (team != null)
+            {
+                team.TeamUsers = new List<TeamUser> { new TeamUser { IsAdmin = teamUser.IsAdmin, AssignedUserId = teamUser.AssignedUserId } };
+
+            }
+            await _unitOfWork.CompleteAsync();
+            
+            return result;
+        }
 
-        //public override async Task<List<TeamDto>> GetAll()
-        //{
-        //    var Teams = await _unitOfWork.Team.GetAllAsync();
-        //    var response = MapperObject.Mapper.Map<List<TeamDto>>(Teams);
-        //    return response;
-        //}
-
-        //public override async Task Delete(long id)
-        //{
-        //    var entity = await _unitOfWork.Team.GetByIdAsync(id);
-        //    await _unitOfWork.Team.DeleteAsync(entity);
-        //}
+       
 
 
 

+ 4 - 1
MTWorkHR.Core/Entities/User/Meeting.cs

@@ -18,7 +18,10 @@ namespace MTWorkHR.Core.Entities
         [MaxLength(500)]
         [Filter]
         public string? Description { get; set; }
-        public DateTime MeetingDateTime { get; set; }
+        public DateTime StartDate { get; set; }
+        public DateTime EndDate { get; set; }
+        [MaxLength(250)]
+        public string? Location { get; set; }
         [MaxLength(250)]
         public string? MeetingLink { get; set; }
         public List<MeetingUser>? MeetingUsers{ get; set; }

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

@@ -17,5 +17,7 @@ namespace MTWorkHR.Core.Entities
         public Team? Team { get; set; }
         [Required]
         public string AssignedUserId { get; set; }
+        public bool IsAdmin { get; set; }
+
     }
 }

+ 1 - 0
MTWorkHR.Core/IRepositories/User/ITeamRepository.cs

@@ -11,6 +11,7 @@ namespace MTWorkHR.Core.IRepositories
     public interface ITeamRepository : IRepository<Team>
     {
         Task<Team> GetByIdWithAllChildren(long id);
+     //   Task<bool> AssignAdminManager(string userId, long teamId, bool isAdmin);
 
     }
 }

File diff suppressed because it is too large
+ 1834 - 0
MTWorkHR.Infrastructure/Migrations/20240305101944_altrTeamMeet.Designer.cs


+ 51 - 0
MTWorkHR.Infrastructure/Migrations/20240305101944_altrTeamMeet.cs

@@ -0,0 +1,51 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrTeamMeet : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.RenameColumn(
+                name: "MeetingDateTime",
+                table: "Meetings",
+                newName: "StartDate");
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "EndDate",
+                table: "Meetings",
+                type: "datetime2",
+                nullable: false,
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
+
+            migrationBuilder.AddColumn<string>(
+                name: "Location",
+                table: "Meetings",
+                type: "nvarchar(250)",
+                maxLength: 250,
+                nullable: true);
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "EndDate",
+                table: "Meetings");
+
+            migrationBuilder.DropColumn(
+                name: "Location",
+                table: "Meetings");
+
+            migrationBuilder.RenameColumn(
+                name: "StartDate",
+                table: "Meetings",
+                newName: "MeetingDateTime");
+        }
+    }
+}

File diff suppressed because it is too large
+ 1837 - 0
MTWorkHR.Infrastructure/Migrations/20240306144054_altrTeam.Designer.cs


+ 29 - 0
MTWorkHR.Infrastructure/Migrations/20240306144054_altrTeam.cs

@@ -0,0 +1,29 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrTeam : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AddColumn<bool>(
+                name: "IsAdmin",
+                table: "TeamUser",
+                type: "bit",
+                nullable: false,
+                defaultValue: false);
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "IsAdmin",
+                table: "TeamUser");
+        }
+    }
+}

+ 12 - 2
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -272,17 +272,24 @@ namespace MTWorkHR.Infrastructure.Migrations
                         .HasMaxLength(500)
                         .HasColumnType("nvarchar(500)");
 
+                    b.Property<DateTime>("EndDate")
+                        .HasColumnType("datetime2");
+
                     b.Property<bool>("IsDeleted")
                         .HasColumnType("bit")
                         .HasColumnOrder(7);
 
-                    b.Property<DateTime>("MeetingDateTime")
-                        .HasColumnType("datetime2");
+                    b.Property<string>("Location")
+                        .HasMaxLength(250)
+                        .HasColumnType("nvarchar(250)");
 
                     b.Property<string>("MeetingLink")
                         .HasMaxLength(250)
                         .HasColumnType("nvarchar(250)");
 
+                    b.Property<DateTime>("StartDate")
+                        .HasColumnType("datetime2");
+
                     b.Property<string>("Title")
                         .IsRequired()
                         .HasMaxLength(250)
@@ -731,6 +738,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                         .HasColumnType("nvarchar(450)")
                         .HasColumnOrder(1);
 
+                    b.Property<bool>("IsAdmin")
+                        .HasColumnType("bit");
+
                     b.Property<long>("TeamId")
                         .HasColumnType("bigint");