Sfoglia il codice sorgente

UserGetAll with companyName

zinab_elgendy 1 mese fa
parent
commit
3d529a8899

+ 1 - 0
MTWorkHR.Application/Dtos/Identity/UserAllDto.cs

@@ -34,6 +34,7 @@ namespace MTWorkHR.Application.Models
         public bool IsStopped { get; set; }
         public string? Position { get; set; }
         public long? CompanyId { get; set; }
+        public string? CompanyName { get; set; }
         public UserTypeEnum UserType { get; set; }
 
 

+ 13 - 0
MTWorkHR.Application/Services/User/UserService.cs

@@ -23,6 +23,7 @@ using MTWorkHR.Infrastructure.EmailService;
 using Countries.NET.Database;
 using Microsoft.AspNetCore.Http;
 using System.Collections;
+using System.Linq;
 
 namespace MTWorkHR.Application.Services
 {
@@ -164,6 +165,8 @@ namespace MTWorkHR.Application.Services
         //}
         public virtual async Task<PagingResultDto<UserAllDto>> GetAll(UserPagingInputDto PagingInputDto)
         {
+            var companies = await _unitOfWork.Company.GetAllAsync();
+           
             var query = _userManager.Users
                 .Include(u => u.Qualification)
                 .Include(u => u.JobTitle)
@@ -225,6 +228,16 @@ namespace MTWorkHR.Application.Services
 
             var list = MapperObject.Mapper.Map<IList<UserAllDto>>(result);
 
+            var ss = list
+             .Join(companies.Item1,               // Join the list with companies.Item1
+                   u => u.CompanyId,               // Key selector for User (CompanyId)
+                   c => c.Id,                      // Key selector for Company (Id)
+                   (u, c) => {                     // Project the join result
+                       u.CompanyName = c.CompanyName;     // Assuming 'Name' is the CompanyName in Company entity
+                       return u;                   // Return the updated UserAllDto with CompanyName filled
+                   })
+             .ToList();
+
             return new PagingResultDto<UserAllDto> { Result = list, Total = total };
         }
         public async Task<List<UserDto>> GetAllEmployees()