Parcourir la source

Chat getCompanyMessages

zinab_elgendy il y a 1 semaine
Parent
commit
a6c7d54b8f

+ 57 - 19
MTWorkHR.Application/Chat/ChatHub.cs

@@ -45,37 +45,62 @@ namespace MTWorkHR.API.Chat
             await Clients.Caller.SendAsync("UpdateUserList", myCompanyUsers);
         }
 
-      
-      
+
+
         public async Task<List<ChatUserDto>> GetAllCompanyEmployees()
         {
-            List<ChatUserDto> response = null;
+            var response = new List<ChatUserDto>();
+
             try
             {
+                // Get all employees with the "Employee" role
                 var employees = await _userManager.GetUsersInRoleAsync("Employee");
+                var companyEmployees = await _userManager.GetUsersInRoleAsync("Employee");
                 var CompanyId = GetAuthenticatedCompanyId();
-                var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
-                var res = employees.Where(e => e.CompanyId == CompanyId && e.Id != userId).ToList();
-            
-                response = MapperObject.Mapper.Map<List<ChatUserDto>>(res);
+                var userId = Context.User.Identities.FirstOrDefault()?.FindFirst("uid")?.Value;
+
+                // Get all message sender and receiver IDs excluding current user
+                var allMessages = await GetAllMessages();
+                var companyUserIds = allMessages
+                    .SelectMany(m => new[] { m.SenderId, m.ReceiverId }).Where(id => id != userId).Distinct().ToHashSet();
+
+                // Filter employees who belong to the same company or have messaged the current user
+                var res = employees.Where(e => e.Id != userId && (e.CompanyId == CompanyId || companyUserIds.Contains(e.Id))).ToList();
 
+                //var mappedEmployees = MapperObject.Mapper.Map<List<ChatUserDto>>(res);
+
+                // Get online users and map to a dictionary for faster lookups
                 var allConnections = await _unitOfWork.HubConnection.GetAllAsync();
-                var onlineUsers = allConnections.Item1
-                    .Select(c => new { c.UserId, c.SignalrId }).ToList();
+                var onlineUsers = allConnections.Item1.ToDictionary(c => c.UserId, c => c.SignalrId);
+
+                // Retrieve last message data for each employee
                 foreach (var emp in res)
                 {
-                    var online = onlineUsers.FirstOrDefault(u => u.UserId == emp.Id);
-                    var profileImg = "";
+                    var onlineSignalrId = onlineUsers.TryGetValue(emp.Id, out var signalrId) ? signalrId : null;
+                    var isOnline = onlineSignalrId != null;
+                    var profileImg = ""; // Assuming this is coming from another source if needed
+
+                    // Retrieve last message and unseen count for the employee
                     var lastMessage = await GetLastMessage(emp.Id);
-                    var lastMsg = lastMessage.Item1?.Content;
-                    var lastMsgDate = lastMessage.Item1?.CreateDate;
-                    var unseenCount = lastMessage.Item2;
-                    var chatUser = new ChatUserDto(emp.Id, emp.FirstName + " " + emp.LastName, online?.SignalrId, emp.Email, online != null ? true : false, profileImg, unseenCount, lastMsg, lastMsgDate);
+
+                    // Create ChatUserDto and add to response
+                    response.Add(new ChatUserDto(
+                        emp.Id,
+                        $"{emp.FirstName} {emp.LastName}",
+                        onlineSignalrId,
+                        emp.Email,
+                        isOnline,
+                        profileImg,
+                        lastMessage.Item2,
+                        lastMessage.Item1?.Content,
+                        lastMessage.Item1?.CreateDate,
+                        emp.FirstName,
+                        emp.LastName
+                    ));
                 }
-            }catch(Exception e)
+            }
+            catch (Exception e)
             {
-                var m = e.Message;
-
                 _logger.LogError(e, e.Message);
             }
 
@@ -107,6 +132,7 @@ namespace MTWorkHR.API.Chat
             await Clients.Caller.SendAsync("PreviousMessages", messagesList);
         }
 
+
         // Send a message from one user to another
 
         public async Task SendMessage(string receiverUserId, string msg)
@@ -135,8 +161,15 @@ namespace MTWorkHR.API.Chat
             catch (Exception e) { _logger.LogError(e, e.Message); }
         }
 
-      
 
+        public async Task<IList<ChatMessage>> GetAllMessages()
+        {
+            var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
+            var allmessages = await _unitOfWork.ChatMessage.GetAllUserMessagesAsync(userId);
+            // Ensure the query is fully materialized before passing it to SignalR
+            var messagesList = await allmessages.Item1.ToListAsync();
+            return messagesList;
+        }
 
         public async Task<Tuple<ChatMessage, int>> GetLastMessage(string contactId)
         {
@@ -178,6 +211,11 @@ namespace MTWorkHR.API.Chat
 
                 if (userId != null) //if credentials are correct
                 {
+                    //--------------delete
+                    var connections = await _unitOfWork.HubConnection.GetAllByUserAsync(userId);
+                    await _unitOfWork.HubConnection.DeleteRangeAsync(connections.Item1.ToList());
+                    await _unitOfWork.CompleteAsync();
+                    //
                     HubConnection currUser = new HubConnection
                     {
                         UserId = userId,

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

@@ -30,10 +30,13 @@ namespace MTWorkHR.Application.Models
             ConnectionId = ConnId;
         }
 
-        public ChatUserDto(string userId, string userName, string ConnId, string email, bool isOnline, string profileImg, int? unseenCount,string lastMessage, DateTime? lastMessageDate)
+        public ChatUserDto(string userId, string userName, string ConnId, string email, bool isOnline, string profileImg, int? unseenCount,string lastMessage, DateTime? lastMessageDate,
+            string firstName, string lastName)
         {
             UserId = userId;
             UserName = userName;
+            FirstName = firstName;
+            LastName = lastName;
             ConnectionId = ConnId;
             Email = email;
             IsOnline = isOnline;

+ 8 - 1
MTWorkHR.Application/Services/User/CompanyService.cs

@@ -29,9 +29,10 @@ namespace MTWorkHR.Application.Services
         private readonly IUserService _userService;
         private readonly IFileService _fileService;
         private readonly ApplicationUserManager _userManager;
+        private readonly RoleManager<ApplicationRole> _roleManager;
 
 
-        public CompanyService(ApplicationUserManager userManager, IUnitOfWork unitOfWork, GlobalInfo globalInfo, AppSettingsConfiguration configuration, IUserService userService, IFileService fileService) : base(unitOfWork)
+        public CompanyService(ApplicationUserManager userManager, IUnitOfWork unitOfWork, GlobalInfo globalInfo, AppSettingsConfiguration configuration, IUserService userService, IFileService fileService, RoleManager<ApplicationRole> roleManager) : base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
             _configuration = configuration;
@@ -39,6 +40,7 @@ namespace MTWorkHR.Application.Services
             _userService = userService;
             _fileService = fileService;
             _userManager = userManager;
+            _roleManager = roleManager;
         }
 
      
@@ -146,6 +148,11 @@ namespace MTWorkHR.Application.Services
             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)

+ 15 - 3
MTWorkHR.Application/Services/User/UserService.cs

@@ -359,11 +359,23 @@ namespace MTWorkHR.Application.Services
             //saving userRoles
             if(input.UserRoles == null || input.UserRoles.Count == 0)
             {
-                var employeeRole = await _roleManager.FindByNameAsync("Employee");
-                if (employeeRole != null)
+                if(user.UserType == (int)UserTypeEnum.Employee)
                 {
-                    await _userManager.AddToRoleAsync(user, "Employee");
+                    var employeeRole = await _roleManager.FindByNameAsync("Employee");
+                    if (employeeRole != null)
+                    {
+                        await _userManager.AddToRoleAsync(user, "Employee");
+                    }
                 }
+                else if (user.UserType == (int)UserTypeEnum.Contractor)
+                {
+                    var employeeRole = await _roleManager.FindByNameAsync("Contractor");
+                    if (employeeRole != null)
+                    {
+                        await _userManager.AddToRoleAsync(user, "Contractor");
+                    }
+                }
+
             }
             else
             {

+ 1 - 0
MTWorkHR.Core/IRepositories/Chat/IHubConnectionRepository.cs

@@ -11,6 +11,7 @@ namespace MTWorkHR.Core.IRepositories
     public interface IHubConnectionRepository : IRepository<HubConnection>
     {
         Task<Tuple<IQueryable<HubConnection>, int>> GetAllAsync(string connectionId);
+        Task<Tuple<IQueryable<HubConnection>, int>> GetAllByUserAsync(string userId);
 
     }
 }

+ 10 - 0
MTWorkHR.Infrastructure/Configurations/RoleConfiguration.cs

@@ -44,6 +44,16 @@ namespace MTWorkHR.Infrastructure.Configurations
                     IsDeleted = false,
 
                 }
+                  ,
+                new ApplicationRole
+                {
+                    Id = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110",
+                    Name = "Business",
+                    NormalizedName = "BUSINESS",
+                    IsAdmin = false,
+                    IsDeleted = false,
+
+                }
 
                 );
         }

+ 47 - 73
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -34,7 +34,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("UsersId");
 
-                    b.ToTable("ApplicationRoleApplicationUser");
+                    b.ToTable("ApplicationRoleApplicationUser", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Attendance", b =>
@@ -103,7 +103,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Attendances");
+                    b.ToTable("Attendances", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.AttendanceLog", b =>
@@ -161,7 +161,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("AttendanceLogs");
+                    b.ToTable("AttendanceLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.AuthLog", b =>
@@ -219,7 +219,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("AuthLogs");
+                    b.ToTable("AuthLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Base.AttachmentType", b =>
@@ -246,7 +246,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("AttachmentTypes");
+                    b.ToTable("AttachmentTypes", (string)null);
 
                     b.HasData(
                         new
@@ -363,7 +363,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ChatMessageId");
 
-                    b.ToTable("ChatAttachment");
+                    b.ToTable("ChatAttachment", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ChatMessage", b =>
@@ -418,7 +418,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("ChatMessages");
+                    b.ToTable("ChatMessages", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.City", b =>
@@ -455,7 +455,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CountryId");
 
-                    b.ToTable("Cities");
+                    b.ToTable("Cities", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Company", b =>
@@ -511,7 +511,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Companies");
+                    b.ToTable("Companies", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Contract", b =>
@@ -646,7 +646,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Contracts");
+                    b.ToTable("Contracts", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractAllowance", b =>
@@ -698,7 +698,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractId");
 
-                    b.ToTable("ContractAllowance");
+                    b.ToTable("ContractAllowance", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractTask", b =>
@@ -749,7 +749,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractId");
 
-                    b.ToTable("ContractTask");
+                    b.ToTable("ContractTask", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractTaskAttachment", b =>
@@ -809,7 +809,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractTaskId");
 
-                    b.ToTable("ContractTaskAttachment");
+                    b.ToTable("ContractTaskAttachment", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.CountryLookup", b =>
@@ -841,7 +841,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("CountryLookups");
+                    b.ToTable("CountryLookups", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.FileLog", b =>
@@ -899,33 +899,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("FileLogs");
-                });
-
-            modelBuilder.Entity("MTWorkHR.Core.Entities.HubConnection", b =>
-                {
-                    b.Property<long>("Id")
-                        .ValueGeneratedOnAdd()
-                        .HasColumnType("bigint")
-                        .HasColumnOrder(0);
-
-                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
-
-                    b.Property<string>("SignalrId")
-                        .HasColumnType("nvarchar(max)");
-
-                    b.Property<DateTime>("TimeStamp")
-                        .HasColumnType("datetime2");
-
-                    b.Property<string>("UserId")
-                        .HasColumnType("nvarchar(max)");
-
-                    b.Property<string>("UserName")
-                        .HasColumnType("nvarchar(max)");
-
-                    b.HasKey("Id");
-
-                    b.ToTable("HubConnections");
+                    b.ToTable("FileLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Industry", b =>
@@ -949,7 +923,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Industries");
+                    b.ToTable("Industries", (string)null);
 
                     b.HasData(
                         new
@@ -1275,7 +1249,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("JobTitles");
+                    b.ToTable("JobTitles", (string)null);
 
                     b.HasData(
                         new
@@ -1446,7 +1420,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("LeaveTypes");
+                    b.ToTable("LeaveTypes", (string)null);
 
                     b.HasData(
                         new
@@ -1511,7 +1485,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("LoginOTPs");
+                    b.ToTable("LoginOTPs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Meeting", b =>
@@ -1588,7 +1562,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Meetings");
+                    b.ToTable("Meetings", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingLog", b =>
@@ -1646,7 +1620,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("MeetingLogs");
+                    b.ToTable("MeetingLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingUser", b =>
@@ -1691,7 +1665,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("MeetingId");
 
-                    b.ToTable("MeetingUser");
+                    b.ToTable("MeetingUser", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.OrderAllocation", b =>
@@ -1748,7 +1722,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("OrderTypeId");
 
-                    b.ToTable("OrderAllocations");
+                    b.ToTable("OrderAllocations", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.OrderType", b =>
@@ -1773,7 +1747,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("OrderTypes");
+                    b.ToTable("OrderTypes", (string)null);
 
                     b.HasData(
                         new
@@ -1842,7 +1816,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Permissions");
+                    b.ToTable("Permissions", (string)null);
 
                     b.HasData(
                         new
@@ -2128,7 +2102,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Projects");
+                    b.ToTable("Projects", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectStage", b =>
@@ -2182,7 +2156,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractId");
 
-                    b.ToTable("ProjectStage");
+                    b.ToTable("ProjectStage", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectStageAttachment", b =>
@@ -2242,7 +2216,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ProjectStageId");
 
-                    b.ToTable("ProjectStageAttachment");
+                    b.ToTable("ProjectStageAttachment", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectTeam", b =>
@@ -2286,7 +2260,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ProjectId");
 
-                    b.ToTable("ProjectTeam");
+                    b.ToTable("ProjectTeam", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Qualification", b =>
@@ -2310,7 +2284,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Qualifications");
+                    b.ToTable("Qualifications", (string)null);
 
                     b.HasData(
                         new
@@ -2388,7 +2362,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("RoleLogs");
+                    b.ToTable("RoleLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.SettingLog", b =>
@@ -2446,7 +2420,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("SettingLogs");
+                    b.ToTable("SettingLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TaskUser", b =>
@@ -2490,7 +2464,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("TaskUser");
+                    b.ToTable("TaskUser", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Team", b =>
@@ -2546,7 +2520,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Teams");
+                    b.ToTable("Teams", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamLog", b =>
@@ -2604,7 +2578,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("TeamLogs");
+                    b.ToTable("TeamLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamUser", b =>
@@ -2652,7 +2626,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TeamId");
 
-                    b.ToTable("TeamUser");
+                    b.ToTable("TeamUser", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.University", b =>
@@ -2676,7 +2650,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Universities");
+                    b.ToTable("Universities", (string)null);
 
                     b.HasData(
                         new
@@ -2780,7 +2754,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("OrderTypeId");
 
-                    b.ToTable("OrderRequests");
+                    b.ToTable("OrderRequests", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserLog", b =>
@@ -2838,7 +2812,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserLogs");
+                    b.ToTable("UserLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTask", b =>
@@ -2912,7 +2886,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("StatusId");
 
-                    b.ToTable("UserTasks");
+                    b.ToTable("UserTasks", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskAttachment", b =>
@@ -2972,7 +2946,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("UserTaskAttachments");
+                    b.ToTable("UserTaskAttachments", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskHistory", b =>
@@ -3024,7 +2998,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("UserTaskHistories");
+                    b.ToTable("UserTaskHistories", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskLog", b =>
@@ -3082,7 +3056,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserTaskLogs");
+                    b.ToTable("UserTaskLogs", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskStatus", b =>
@@ -3106,7 +3080,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserTaskStatuses");
+                    b.ToTable("UserTaskStatuses", (string)null);
 
                     b.HasData(
                         new
@@ -3452,7 +3426,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("RoleId");
 
-                    b.ToTable("RolePermissions");
+                    b.ToTable("RolePermissions", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.UserAddress", b =>
@@ -3507,7 +3481,7 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.HasIndex("UserId")
                         .IsUnique();
 
-                    b.ToTable("UserAddress");
+                    b.ToTable("UserAddress", (string)null);
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.UserAttachment", b =>
@@ -3570,7 +3544,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("UserId");
 
-                    b.ToTable("UserAttachments");
+                    b.ToTable("UserAttachments", (string)null);
                 });
 
             modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>

+ 10 - 2
MTWorkHR.Infrastructure/Repositories/Chat/HubConnectionRepository.cs

@@ -18,13 +18,21 @@ namespace MTWorkHR.Infrastructure.Repositories
 
         public async Task<Tuple<IQueryable<HubConnection>, int>> GetAllAsync(string connectionId)
         {
-            var query = dbSet.AsQueryable();
+            var query = dbSet.Where(c=> c.SignalrId == connectionId).AsQueryable();
             var total = await query.CountAsync();
 
             return new Tuple<IQueryable<HubConnection>, int>(query, total);
         }
 
-       
+        public async Task<Tuple<IQueryable<HubConnection>, int>> GetAllByUserAsync(string userId)
+        {
+            var query = dbSet.Where(c=> c.UserId == userId).AsQueryable();
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<HubConnection>, int>(query, total);
+        }
+
+
 
     }
 }