Procházet zdrojové kódy

Chat Change ChatUser

zinab_elgendy před 1 měsícem
rodič
revize
ec75cfbf67

+ 13 - 2
MTWorkHR.Application/Chat/ChatHub.cs

@@ -45,12 +45,23 @@ namespace MTWorkHR.API.Chat
 
       
       
-        public async Task<List<UserAllDto>> GetAllCompanyEmployees()
+        public async Task<List<ChatUserDto>> GetAllCompanyEmployees()
         {
             var employees = await _userManager.GetUsersInRoleAsync("Employee");
             var CompanyId = GetAuthenticatedCompanyId();
             var res = employees.Where(e => e.CompanyId == CompanyId).ToList();
-            var response = MapperObject.Mapper.Map<List<UserAllDto>>(res);
+
+            var response = MapperObject.Mapper.Map<List<ChatUserDto>>(res);
+
+            var allConnections = await _unitOfWork.HubConnection.GetAllAsync();
+            var onlineUsers = allConnections.Item1
+                .Select(c => new { c.UserId, c.SignalrId }).ToList();
+            foreach(var emp in res)
+            {
+                var online = onlineUsers.FirstOrDefault(u=>  u.UserId == emp.Id);
+                var profileImg = "";
+                var chatUser = new ChatUserDto(emp.Id, emp.FirstName + " " + emp.LastName, online?.SignalrId, emp.Email, online != null ? true : false, profileImg);
+            }
 
             return response;
         }

+ 17 - 1
MTWorkHR.Application/Dtos/User/ChatUserDto.cs

@@ -11,12 +11,28 @@ namespace MTWorkHR.Application.Models
         public string UserId { get; set; }
         public string UserName { get; set; }
         public string ConnectionId { get; set; } //signalrId
-
+        public string FirstName { get; set; }
+        public string LastName { get; set; }
+        public string FavoriteName { get; set; }
+        public string PhoneNumber { get; set; }
+        public string Email { get; set; }
+        public bool IsOnline { get; set; }
+        public string? ProfileImage { get; set; }
         public ChatUserDto(string someId, string someName, string someConnId)
         {
             UserId = someId;
             UserName = someName;
             ConnectionId = someConnId;
         }
+
+        public ChatUserDto(string someId, string userName, string ConnId, string email, bool isOnline, string profileImg)
+        {
+            UserId = someId;
+            UserName = userName;
+            ConnectionId = ConnId;
+            Email = email;
+            IsOnline = isOnline;
+            ProfileImage = profileImg;
+        }
     }
 }

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

@@ -31,6 +31,7 @@ namespace MTWorkHR.Application.Identity
         Task<List<UserAllDto>> GetAllCompanyEmployees();
         Task<BlobObject> Download(string filePath);
         Task<UserDto> GetUserWithAttachmentById(string id);
+        Task<string> GetProfileImage(string userId);
 
     }
 }

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

@@ -152,6 +152,19 @@ namespace MTWorkHR.Application.Services
 
             return response;
         }
+
+        public async Task<string> GetProfileImage(string userId)
+        {
+            string imagePath = null;
+            var user = await _userManager.Users.Include(u => u.UserAttachments)
+                .FirstOrDefaultAsync(x => x.Id == userId);
+            if (user != null)
+            {
+                var imageAtt = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
+                imagePath = imageAtt != null ? imageAtt.FilePath : "";
+            }
+            return imagePath;
+        }
         //public async Task<List<UserDto>> GetAll(PagingInputDto pagingInput)
         //{
         //    var employees = await _userManager.GetUsersInRoleAsync("Employee");