zinab_elgendy преди 1 месец
родител
ревизия
84e8660748
променени са 2 файла, в които са добавени 11 реда и са изтрити 9 реда
  1. 9 8
      MTWorkHR.Application/Chat/Chat.cs
  2. 2 1
      MTWorkHR.Core/Entities/Chat/Connection.cs

+ 9 - 8
MTWorkHR.Application/Chat/Chat.cs

@@ -1,5 +1,6 @@
 using Microsoft.AspNetCore.SignalR;
 using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Models;
 using MTWorkHR.Core.Global;
 using MTWorkHR.Core.UnitOfWork;
 
@@ -15,14 +16,14 @@ namespace MTWorkHR.API.Chat
         }
         public async Task getOnlineUsers()
         {
-            //var allConnections = await _unitOfWork.Connection.GetAllAsync();
-            //var currUserId = allConnections.Item1.Where(c => c.SignalrId == Context.ConnectionId).Select(c => c.UserId).SingleOrDefault();
-            //List<User> onlineUsers = allConnections
-            //    .Where(c => c.PersonId != currUserId)
-            //    .Select(c =>
-            //        new UserDto(c.PersonId, ctx.Person.Where(p => p.Id == c.PersonId).Select(p => p.Name).SingleOrDefault(), c.SignalrId)
-            //    ).ToList();
-            //await Clients.Caller.SendAsync("getOnlineUsersResponse", onlineUsers);
+            var allConnections = await _unitOfWork.Connection.GetAllAsync();
+            var currUserId = allConnections.Item1.Where(c => c.SignalrId == Context.ConnectionId).Select(c => c.UserId).SingleOrDefault();
+            List<UserDto> onlineUsers = allConnections.Item1
+                .Where(c => c.UserId != currUserId)
+                .Select(c =>
+                    new UserDto { Id = c.UserId, UserName = c.UserName /*, c.SignalrId*/ }
+                ).ToList();
+            await Clients.Caller.SendAsync("getOnlineUsersResponse", onlineUsers);
         }
 
 

+ 2 - 1
MTWorkHR.Core/Entities/Chat/Connection.cs

@@ -8,7 +8,8 @@ namespace MTWorkHR.Core.Entities
 {
     public partial class Connection : Entity
     {
-        public Guid UserId { get; set; }
+        public string UserId { get; set; }
+        public string UserName { get; set; }
         public string SignalrId { get; set; }
         public DateTime TimeStamp { get; set; }
     }