소스 검색

CompanyUserGetMessages

zinab_elgendy 1 개월 전
부모
커밋
468d072d2e

+ 27 - 10
MTWorkHR.Application/Chat/ChatHub.cs

@@ -53,28 +53,36 @@ namespace MTWorkHR.API.Chat
 
             try
             {
-                // Get all employees with the "Employee" role
-                var employees = await _userManager.GetUsersInRoleAsync("Employee");
-                var companyEmployees = await _userManager.GetUsersInRoleAsync("Employee");
+                // Get all employees with "Employee" and "Business" roles
+                var employeesInRole = await _userManager.GetUsersInRoleAsync("Employee");
+                var businessInRole = await _userManager.GetUsersInRoleAsync("Business");
+
+                // Combine employee lists if needed and apply unique filtering based on IDs
+                var allEmployees = employeesInRole.Union(businessInRole).DistinctBy(e => e.Id).ToList();
+
                 var CompanyId = GetAuthenticatedCompanyId();
                 var userId = Context.User.Identities.FirstOrDefault()?.FindFirst("uid")?.Value;
 
-                // Get all message sender and receiver IDs excluding current user
+                // Get all message sender and receiver IDs excluding the current user
                 var allMessages = await GetAllMessages();
                 var companyUserIds = allMessages
-                    .SelectMany(m => new[] { m.SenderId, m.ReceiverId }).Where(id => id != userId).Distinct().ToHashSet();
+                    .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);
+                // Filter all employees by CompanyId or if they have messaged the user
+                var employeesToChat = allEmployees
+                    .Where(e => e.Id != userId &&
+                               (e.CompanyId == CompanyId || companyUserIds.Contains(e.Id)))
+                    .ToList();
 
                 // Get online users and map to a dictionary for faster lookups
                 var allConnections = await _unitOfWork.HubConnection.GetAllAsync();
                 var onlineUsers = allConnections.Item1.ToDictionary(c => c.UserId, c => c.SignalrId);
 
                 // Retrieve last message data for each employee
-                foreach (var emp in res)
+                foreach (var emp in employeesToChat)
                 {
                     var onlineSignalrId = onlineUsers.TryGetValue(emp.Id, out var signalrId) ? signalrId : null;
                     var isOnline = onlineSignalrId != null;
@@ -183,6 +191,15 @@ namespace MTWorkHR.API.Chat
         //----------------------------------------------------------------------
         //----------------------------------------------------------------------
         //----------------------------------------------------------------------
+        public async Task<bool> MarkAsSeen(long messageId)
+        {
+            //var userId = Context.User.Identities.FirstOrDefault().FindFirst("uid")?.Value;
+            var message = await _unitOfWork.ChatMessage.GetByIdAsync(messageId);
+            message.IsSeen = true;
+            await _unitOfWork.CompleteAsync();
+
+            return true;
+        }
 
         //Simple Test Method
         public async Task SendMessageAll(string user, string message)

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 5698 - 0
MTWorkHR.Infrastructure/Migrations/20241103150423_altrRoleBusiness.Designer.cs


+ 32 - 0
MTWorkHR.Infrastructure/Migrations/20241103150423_altrRoleBusiness.cs

@@ -0,0 +1,32 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrRoleBusiness : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+           
+            migrationBuilder.InsertData(
+                table: "AspNetRoles",
+                columns: new[] { "Id", "ConcurrencyStamp", "CreateDate", "CreateUser", "DeleteUserId", "IsAdmin", "IsDeleted", "Name", "NormalizedName", "UpdateDate", "UpdateUser" },
+                values: new object[] { "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110", null, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, false, false, "Business", "BUSINESS", null, null });
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+         
+
+            migrationBuilder.DeleteData(
+                table: "AspNetRoles",
+                keyColumn: "Id",
+                keyValue: "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110");
+        }
+    }
+}

+ 81 - 46
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -34,7 +34,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("UsersId");
 
-                    b.ToTable("ApplicationRoleApplicationUser", (string)null);
+                    b.ToTable("ApplicationRoleApplicationUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Attendance", b =>
@@ -103,7 +103,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Attendances", (string)null);
+                    b.ToTable("Attendances");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.AttendanceLog", b =>
@@ -161,7 +161,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("AttendanceLogs", (string)null);
+                    b.ToTable("AttendanceLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.AuthLog", b =>
@@ -219,7 +219,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("AuthLogs", (string)null);
+                    b.ToTable("AuthLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Base.AttachmentType", b =>
@@ -246,7 +246,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("AttachmentTypes", (string)null);
+                    b.ToTable("AttachmentTypes");
 
                     b.HasData(
                         new
@@ -363,7 +363,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ChatMessageId");
 
-                    b.ToTable("ChatAttachment", (string)null);
+                    b.ToTable("ChatAttachment");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ChatMessage", b =>
@@ -418,7 +418,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("ChatMessages", (string)null);
+                    b.ToTable("ChatMessages");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.City", b =>
@@ -455,7 +455,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CountryId");
 
-                    b.ToTable("Cities", (string)null);
+                    b.ToTable("Cities");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Company", b =>
@@ -674,7 +674,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Contracts", (string)null);
+                    b.ToTable("Contracts");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractAllowance", b =>
@@ -726,7 +726,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractId");
 
-                    b.ToTable("ContractAllowance", (string)null);
+                    b.ToTable("ContractAllowance");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractTask", b =>
@@ -777,7 +777,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractId");
 
-                    b.ToTable("ContractTask", (string)null);
+                    b.ToTable("ContractTask");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ContractTaskAttachment", b =>
@@ -837,7 +837,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractTaskId");
 
-                    b.ToTable("ContractTaskAttachment", (string)null);
+                    b.ToTable("ContractTaskAttachment");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.CountryLookup", b =>
@@ -869,7 +869,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("CountryLookups", (string)null);
+                    b.ToTable("CountryLookups");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.FileLog", b =>
@@ -927,7 +927,33 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("FileLogs", (string)null);
+                    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");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Industry", b =>
@@ -951,7 +977,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Industries", (string)null);
+                    b.ToTable("Industries");
 
                     b.HasData(
                         new
@@ -1277,7 +1303,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("JobTitles", (string)null);
+                    b.ToTable("JobTitles");
 
                     b.HasData(
                         new
@@ -1448,7 +1474,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("LeaveTypes", (string)null);
+                    b.ToTable("LeaveTypes");
 
                     b.HasData(
                         new
@@ -1513,7 +1539,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("LoginOTPs", (string)null);
+                    b.ToTable("LoginOTPs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Meeting", b =>
@@ -1590,7 +1616,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Meetings", (string)null);
+                    b.ToTable("Meetings");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingLog", b =>
@@ -1648,7 +1674,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("MeetingLogs", (string)null);
+                    b.ToTable("MeetingLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingUser", b =>
@@ -1693,7 +1719,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("MeetingId");
 
-                    b.ToTable("MeetingUser", (string)null);
+                    b.ToTable("MeetingUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Nationality", b =>
@@ -3231,7 +3257,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("OrderTypeId");
 
-                    b.ToTable("OrderAllocations", (string)null);
+                    b.ToTable("OrderAllocations");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.OrderType", b =>
@@ -3256,7 +3282,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("OrderTypes", (string)null);
+                    b.ToTable("OrderTypes");
 
                     b.HasData(
                         new
@@ -3325,7 +3351,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Permissions", (string)null);
+                    b.ToTable("Permissions");
 
                     b.HasData(
                         new
@@ -3611,7 +3637,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Projects", (string)null);
+                    b.ToTable("Projects");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectStage", b =>
@@ -3665,7 +3691,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ContractId");
 
-                    b.ToTable("ProjectStage", (string)null);
+                    b.ToTable("ProjectStage");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectStageAttachment", b =>
@@ -3725,7 +3751,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ProjectStageId");
 
-                    b.ToTable("ProjectStageAttachment", (string)null);
+                    b.ToTable("ProjectStageAttachment");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectTeam", b =>
@@ -3769,7 +3795,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ProjectId");
 
-                    b.ToTable("ProjectTeam", (string)null);
+                    b.ToTable("ProjectTeam");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Qualification", b =>
@@ -3793,7 +3819,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Qualifications", (string)null);
+                    b.ToTable("Qualifications");
 
                     b.HasData(
                         new
@@ -3871,7 +3897,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("RoleLogs", (string)null);
+                    b.ToTable("RoleLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.SettingLog", b =>
@@ -3929,7 +3955,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("SettingLogs", (string)null);
+                    b.ToTable("SettingLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TaskUser", b =>
@@ -3973,7 +3999,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("TaskUser", (string)null);
+                    b.ToTable("TaskUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Team", b =>
@@ -4029,7 +4055,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Teams", (string)null);
+                    b.ToTable("Teams");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamLog", b =>
@@ -4087,7 +4113,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("TeamLogs", (string)null);
+                    b.ToTable("TeamLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamUser", b =>
@@ -4135,7 +4161,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TeamId");
 
-                    b.ToTable("TeamUser", (string)null);
+                    b.ToTable("TeamUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.University", b =>
@@ -4159,7 +4185,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Universities", (string)null);
+                    b.ToTable("Universities");
 
                     b.HasData(
                         new
@@ -4263,7 +4289,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("OrderTypeId");
 
-                    b.ToTable("OrderRequests", (string)null);
+                    b.ToTable("OrderRequests");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserLog", b =>
@@ -4321,7 +4347,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserLogs", (string)null);
+                    b.ToTable("UserLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTask", b =>
@@ -4395,7 +4421,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("StatusId");
 
-                    b.ToTable("UserTasks", (string)null);
+                    b.ToTable("UserTasks");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskAttachment", b =>
@@ -4455,7 +4481,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("UserTaskAttachments", (string)null);
+                    b.ToTable("UserTaskAttachments");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskHistory", b =>
@@ -4507,7 +4533,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("UserTaskHistories", (string)null);
+                    b.ToTable("UserTaskHistories");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskLog", b =>
@@ -4565,7 +4591,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserTaskLogs", (string)null);
+                    b.ToTable("UserTaskLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskStatus", b =>
@@ -4589,7 +4615,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserTaskStatuses", (string)null);
+                    b.ToTable("UserTaskStatuses");
 
                     b.HasData(
                         new
@@ -4692,6 +4718,15 @@ namespace MTWorkHR.Infrastructure.Migrations
                             IsDeleted = false,
                             Name = "Contractor",
                             NormalizedName = "CONTRACTOR"
+                        },
+                        new
+                        {
+                            Id = "BS5B3B92-2311-48F8-9DEC-F9FAEF1F2110",
+                            CreateDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
+                            IsAdmin = false,
+                            IsDeleted = false,
+                            Name = "Business",
+                            NormalizedName = "BUSINESS"
                         });
                 });
 
@@ -4946,7 +4981,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("RoleId");
 
-                    b.ToTable("RolePermissions", (string)null);
+                    b.ToTable("RolePermissions");
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.UserAddress", b =>
@@ -5001,7 +5036,7 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.HasIndex("UserId")
                         .IsUnique();
 
-                    b.ToTable("UserAddress", (string)null);
+                    b.ToTable("UserAddress");
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.UserAttachment", b =>
@@ -5064,7 +5099,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("UserId");
 
-                    b.ToTable("UserAttachments", (string)null);
+                    b.ToTable("UserAttachments");
                 });
 
             modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>