Преглед изворни кода

Mapper :ApplicationUser, ChatUserDto

zinab_elgendy пре 2 недеља
родитељ
комит
2992a7661d

+ 7 - 5
MTWorkHR.Application/Chat/ChatHub.cs

@@ -49,7 +49,8 @@ namespace MTWorkHR.API.Chat
         {
             var employees = await _userManager.GetUsersInRoleAsync("Employee");
             var CompanyId = GetAuthenticatedCompanyId();
-            var res = employees.Where(e => e.CompanyId == CompanyId).ToList();
+            var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
+            var res = employees.Where(e => e.CompanyId == CompanyId && e.Id != userId).ToList();
 
             var response = MapperObject.Mapper.Map<List<ChatUserDto>>(res);
 
@@ -60,8 +61,9 @@ namespace MTWorkHR.API.Chat
             {
                 var online = onlineUsers.FirstOrDefault(u=>  u.UserId == emp.Id);
                 var profileImg = "";
-                var lastMsg = "";
-                var lastMsgDate = "";
+                var lastMessage = await GetLastMessage(emp.Id);
+                var lastMsg = lastMessage.Content;
+                var lastMsgDate = lastMessage.CreateDate;
                 var unseenCount = 0;
                 var chatUser = new ChatUserDto(emp.Id, emp.FirstName + " " + emp.LastName, online?.SignalrId, emp.Email, online != null ? true : false, profileImg, unseenCount,lastMsg,lastMsgDate);
             }
@@ -125,10 +127,10 @@ namespace MTWorkHR.API.Chat
         }
 
 
-        public async Task<ChatMessage> GetLastMessage()
+        public async Task<ChatMessage> GetLastMessage(string contactId)
         {
             var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
-            var allmessages = await _unitOfWork.ChatMessage.GetAllUserMessagesAsync(userId);
+            var allmessages = await _unitOfWork.ChatMessage.GetAllWithChildrenAsync(userId, contactId);
             // Ensure the query is fully materialized before passing it to SignalR
             var lastOne = allmessages.Item1.LastOrDefault();
 

+ 2 - 0
MTWorkHR.Application/Mapper/MappingProfile.cs

@@ -53,6 +53,8 @@ namespace MTWorkHR.Application.Mapper
             CreateMap<UserDto, UserUpdateDto>().ReverseMap();
             CreateMap<UserBasicInfoDto, ApplicationUser>().ReverseMap();
             CreateMap<UserBasicInfoDto, UserDto>().ReverseMap();
+
+            CreateMap<ApplicationUser, ChatUserDto>().ReverseMap();
             
             CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
             CreateMap<UserAddress, UserAddressDto>()