zinab_elgendy 2 月之前
父节点
当前提交
18143dcd0b

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

@@ -72,7 +72,15 @@ namespace MTWorkHR.API.Controllers
             return await _TeamService.AssignAdminManager(teamUser);
         }
 
+        [HttpGet("GetTeamListForUser")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        [AppAuthorize(Permissions = "Team.Update")]
+        public async Task<IList<TeamDto>> GetTeamListForUser(string userId)
+        {
+            return await _TeamService.GetTeamListForUser(userId);
+        }
 
+        
 
     }
 }

+ 1 - 1
MTWorkHR.API/Program.cs

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

+ 1 - 0
MTWorkHR.Application/Dtos/Contract/ContractDto.cs

@@ -74,6 +74,7 @@ namespace MTWorkHR.Application.Models
         public DateTime? LastPatchDateFrom { get; set; } //
         public DateTime? LastPatchDateTo { get; set; } // 
         public decimal? LastPatchAmount { get; set; }
+        public string? Teams{ get; set; }
 
 
 

+ 32 - 1
MTWorkHR.Application/Services/Contract/ContractService.cs

@@ -9,6 +9,7 @@ using MTWorkHR.Core.Entities;
 using System.Linq.Dynamic.Core;
 using Microsoft.AspNetCore.Identity;
 using MTWorkHR.Infrastructure.Entities;
+using System.Linq;
 
 namespace MTWorkHR.Application.Services
 {
@@ -17,6 +18,7 @@ namespace MTWorkHR.Application.Services
         private readonly IUnitOfWork _unitOfWork;
         private readonly IUserService _userService;
         private readonly GlobalInfo _globalInfo;
+        private readonly OrderAllocationService _orderAllocationService;
 
         public ContractService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo) : base(unitOfWork)
         {
@@ -69,6 +71,22 @@ namespace MTWorkHR.Application.Services
             var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
             var query = res.Item1;
 
+
+           
+            //var query = queryx
+            //     .Join(
+            //         teamUsersList.Item1,
+            //         c => c.UserId,
+            //         teamUser => teamUser.AssignedUserId,
+            //         (contract, teamUser) => new
+            //         {
+            //             Contract = contract,
+            //             Teams = teamUser.Team.NameEn
+            //         }
+            //     )
+            //     .AsQueryable();
+
+
             if (_globalInfo.UserType != UserTypeEnum.Business)
             {
                // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
@@ -97,7 +115,7 @@ namespace MTWorkHR.Application.Services
 
             var list = MapperObject.Mapper
                 .Map<IList<ContractDto>>(await page.ToListAsync());
-
+            
             foreach (var item in list)
             {
                 if (item.UserId != null)
@@ -110,6 +128,14 @@ namespace MTWorkHR.Application.Services
                     }
                 }
             }
+            var teamUsersList = await _unitOfWork.TeamUser.GetAllWithChildrenAsync();
+            foreach (var item in list)
+            {
+                if (item.UserId != null)
+                {
+                   item.Teams = teamUsersList.Item1.Where(t => t.AssignedUserId == item.UserId).Select(t=> t.Team.NameEn).Aggregate((a,b)=> a+","+b);
+                }
+            }
             var response = new PagingResultDto<ContractDto>
             {
                 Result = list,
@@ -129,12 +155,17 @@ namespace MTWorkHR.Application.Services
             if (statusId == (int)ContractStatusEnum.Approved)
             {
                 var updatedSuccess = await _userService.Update(entity.UserId, entity.CompanyId);
+                addVacationAllocation(entity.VacationDays.HasValue ? entity.VacationDays.Value : 0, entity.UserId);
                 if (!updatedSuccess) { result = false; }
             }
             await _unitOfWork.CompleteAsync();
             return result;
         }
 
+        private void addVacationAllocation(int noVacationDays, string employeeId)
+        {
+            _orderAllocationService.Create(new OrderAllocationDto { EmployeeId = employeeId,OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year});
+        }
 
 
     }

+ 2 - 0
MTWorkHR.Application/Services/Interfaces/ILeaveAllocationService.cs

@@ -7,5 +7,7 @@ namespace MTWorkHR.Application.Services.Interfaces
 {
     public interface IOrderAllocationService : IService<OrderAllocation, OrderAllocationDto, OrderAllocationDto>
     {
+        Task<OrderAllocationDto> CreateAllEmployees(OrderAllocationDto input);
+
     }
 }

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

@@ -9,6 +9,6 @@ namespace MTWorkHR.Application.Services.Interfaces
     {
         Task<bool> AssignAdminManager(TeamUserDto teamUser);
         Task<string> GetTeamName(long teamId);
-       
+        Task<IList<TeamDto>> GetTeamListForUser(string userId);
     }
 }

+ 10 - 9
MTWorkHR.Application/Services/User/CompanyService.cs

@@ -164,15 +164,7 @@ namespace MTWorkHR.Application.Services
 
             // var userResp = await _userService.Create(companyUser);
             var user = MapperObject.Mapper.Map<ApplicationUser>(companyUser);
-            if (user.UserType == 0)
-            {
-                user.UserType = (int)UserTypeEnum.Business;
-                var employeeRole = await _roleManager.FindByNameAsync("Business");
-                if (employeeRole != null)
-                {
-                    await _userManager.AddToRoleAsync(user, "Business");
-                }
-            }
+            
             var result = await _userManager.CreateAsync(user, companyUser.Password);
             if (!result.Succeeded)
             {
@@ -183,6 +175,15 @@ namespace MTWorkHR.Application.Services
                 }
                 throw new AppException(ExceptionEnum.RecordCreationFailed);
             }
+            if (user.UserType == 0)
+            {
+                user.UserType = (int)UserTypeEnum.Business;
+                var employeeRole = await _roleManager.FindByNameAsync("Business");
+                if (employeeRole != null)
+                {
+                    await _userManager.AddToRoleAsync(user, "Business");
+                }
+            }
             return user;
         }
 

+ 1 - 1
MTWorkHR.Application/Services/User/OrderAllocationService.cs

@@ -36,7 +36,7 @@ namespace MTWorkHR.Application.Services
         }
 
 
-        public override async Task<OrderAllocationDto> Create(OrderAllocationDto input)
+        public async Task<OrderAllocationDto> CreateAllEmployees(OrderAllocationDto input)
         {
             try
             {

+ 10 - 0
MTWorkHR.Application/Services/User/TeamService.cs

@@ -15,6 +15,7 @@ using MTWorkHR.Core.Entities;
 using MTWorkHR.Infrastructure.UnitOfWorks;
 using System.Linq;
 using System.Linq.Dynamic.Core;
+using MTWorkHR.Core.Entities.Base;
 
 namespace MTWorkHR.Application.Services
 {
@@ -159,5 +160,14 @@ namespace MTWorkHR.Application.Services
             return name;
         }
 
+        public async Task<IList<TeamDto>> GetTeamListForUser(string userId)
+        {
+            var teamsList = await _unitOfWork.TeamUser.GetUserTeams(userId);
+            var result = teamsList.Item1;
+
+            var response = Mapper.MapperObject.Mapper.Map<IList<TeamDto>>(result);
+            return response;
+        }
+
     }
 }

+ 3 - 0
MTWorkHR.Core/IRepositories/User/ITeamUserRepository.cs

@@ -17,5 +17,8 @@ namespace MTWorkHR.Core.IRepositories
         Task<IList<TeamUser>> AddRangeAsync(IList<TeamUser> entity);
         Task DeleteAsync(TeamUser entity);
         Task DeleteAsync(IEnumerable<TeamUser> entities);
+
+        Task<Tuple<IQueryable<TeamUser>, int>> GetAllWithChildrenAsync();
+        Task<Tuple<IQueryable<Team>, int>> GetUserTeams(string userId);
     }
 }

+ 4 - 4
MTWorkHR.Infrastructure/Configurations/RolePermissionConfiguration.cs

@@ -41,12 +41,12 @@ namespace MTWorkHR.Infrastructure.Configurations
                 new RolePermission { Id = 16, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 16, PermissionName = "UserTask.Delete" },
 
                 // Company permissions (excluding Delete and Suspend)
-                //new RolePermission { Id = 17, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 17, PermissionName = "Company" },
+                new RolePermission { Id = 17, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 17, PermissionName = "Company" },
                 //new RolePermission { Id = 18, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 18, PermissionName = "Company.Create" },
                 //new RolePermission { Id = 19, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 19, PermissionName = "Company.Update" },
 
                 // User permissions (excluding Delete and Suspend)
-                //new RolePermission { Id = 20, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 22, PermissionName = "User" },
+                new RolePermission { Id = 20, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 22, PermissionName = "User" },
                 //new RolePermission { Id = 21, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 23, PermissionName = "User.Create" },
                 //new RolePermission { Id = 22, RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E", PermissionId = 24, PermissionName = "User.Update" },
 
@@ -113,12 +113,12 @@ namespace MTWorkHR.Infrastructure.Configurations
                 new RolePermission { Id = 64, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 16, PermissionName = "UserTask.Delete" },
 
                 // Company permissions (excluding Delete and Suspend)
-                //new RolePermission { Id = 65, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 17, PermissionName = "Company" },
+                new RolePermission { Id = 65, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 17, PermissionName = "Company" },
                 //new RolePermission { Id = 66, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 18, PermissionName = "Company.Create" },
                 //new RolePermission { Id = 67, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 19, PermissionName = "Company.Update" },
 
                 // User permissions (excluding Delete and Suspend)
-                //new RolePermission { Id = 68, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 22, PermissionName = "User" },
+                new RolePermission { Id = 68, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 22, PermissionName = "User" },
                 //new RolePermission { Id = 69, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 23, PermissionName = "User.Create" },
                 //new RolePermission { Id = 70, RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R", PermissionId = 24, PermissionName = "User.Update" },
 

+ 1 - 1
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

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

文件差异内容过多而无法显示
+ 6840 - 0
MTWorkHR.Infrastructure/Migrations/20250122125207_altrPermissionGet.Designer.cs


+ 51 - 0
MTWorkHR.Infrastructure/Migrations/20250122125207_altrPermissionGet.cs

@@ -0,0 +1,51 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrPermissionGet : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.InsertData(
+                table: "RolePermissions",
+                columns: new[] { "Id", "PermissionId", "PermissionName", "RoleId" },
+                values: new object[,]
+                {
+                    { 17L, 17L, "Company", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 20L, 22L, "User", "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E" },
+                    { 65L, 17L, "Company", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" },
+                    { 68L, 22L, "User", "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R" }
+                });
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 17L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 20L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 65L);
+
+            migrationBuilder.DeleteData(
+                table: "RolePermissions",
+                keyColumn: "Id",
+                keyValue: 68L);
+        }
+    }
+}

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

@@ -5376,6 +5376,20 @@ namespace MTWorkHR.Infrastructure.Migrations
                         },
                         new
                         {
+                            Id = 17L,
+                            PermissionId = 17L,
+                            PermissionName = "Company",
+                            RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E"
+                        },
+                        new
+                        {
+                            Id = 20L,
+                            PermissionId = 22L,
+                            PermissionName = "User",
+                            RoleId = "EM5B3B92-2311-48F8-9DEC-F9FAEF1F211E"
+                        },
+                        new
+                        {
                             Id = 23L,
                             PermissionId = 27L,
                             PermissionName = "Role",
@@ -5642,6 +5656,20 @@ namespace MTWorkHR.Infrastructure.Migrations
                         },
                         new
                         {
+                            Id = 65L,
+                            PermissionId = 17L,
+                            PermissionName = "Company",
+                            RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R"
+                        },
+                        new
+                        {
+                            Id = 68L,
+                            PermissionId = 22L,
+                            PermissionName = "User",
+                            RoleId = "CO5B3B92-2311-48F8-9DEC-F9FAEF1F211R"
+                        },
+                        new
+                        {
                             Id = 71L,
                             PermissionId = 27L,
                             PermissionName = "Role",

+ 34 - 1
MTWorkHR.Infrastructure/Repositories/Contract/ContractRepository.cs

@@ -10,9 +10,11 @@ namespace MTWorkHR.Infrastructure.Repositories
     public class ContractRepository : Repository<Contract>, IContractRepository
     {
         private readonly DbSet<Contract> dbSet;
+        private readonly DbSet<TeamUser> dbSet2;
         public ContractRepository(HRDataContext context) : base(context)
         {
             dbSet = context.Set<Contract>();
+            dbSet2 = context.Set<TeamUser>();
 
         }
         public async Task<Contract> GetByIdWithAllChildren(long id)
@@ -28,11 +30,42 @@ namespace MTWorkHR.Infrastructure.Repositories
 
         public async Task<Tuple<IQueryable<Contract>, int>> GetAllWithChildrenAsync()
         {
-            var query = dbSet//.Include(x => x.ContractUsers)
+            var query = dbSet//.Join(x => x.TeamUser)
                 .AsQueryable();
+
+
+
+
             var total = await query.CountAsync();
 
             return new Tuple<IQueryable<Contract>, int>(query, total);
         }
+
+        public async Task<Tuple<IQueryable<Contract>, int>> GetAllWithTeamsAsync()
+        {
+            var query = dbSet//.Join(x => x.TeamUser)
+              .AsQueryable();
+
+            //var teamUsersList = dbSet2.Include(x => x.Team).ToList();
+            var query2 = dbSet
+                 .Join(
+                     dbSet2.Include(x => x.Team),
+                     c => c.UserId,
+                     teamUser => teamUser.AssignedUserId,
+                     (contract, teamUser) => new
+                     {
+                         Contract = contract,
+                         Team = teamUser.Team.NameEn
+                     }
+                 )
+                 .AsQueryable();
+
+
+
+
+            var total = await query2.CountAsync();
+
+            return new Tuple<IQueryable<Contract>, int>(query, total);
+        }
     }
 }

+ 20 - 0
MTWorkHR.Infrastructure/Repositories/User/TeamUserRepository.cs

@@ -37,5 +37,25 @@ namespace MTWorkHR.Infrastructure.Repositories
         {
             dbSet.RemoveRange(entities);
         }
+
+
+        public async Task<Tuple<IQueryable<Team>, int>> GetUserTeams(string userId)
+        {
+            var query = dbSet.Where(u=> u.AssignedUserId == userId).Select(t=> t.Team).AsQueryable();
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<Team>, int>(query, total);
+        }
+
+
+        public async Task<Tuple<IQueryable<TeamUser>, int>> GetAllWithChildrenAsync()
+        {
+            var query = dbSet.Include(x => x.Team)
+                .AsQueryable();
+
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<TeamUser>, int>(query, total);
+        }
     }
 }