zinab_elgendy 2 months ago
parent
commit
c8b1edf32d

+ 4 - 1
MTWorkHR.API/appsettings.Development.json

@@ -6,7 +6,10 @@
     }
   },
   "ConnectionStrings": {
-    "LocalConnectionString": "Server=.;Database=MTWorkHRDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true;Integrated Security=True;Encrypt=False"
+    "MTWorkHRConnectionString": "Server=tcp:mtworksqlserver.database.windows.net,1433;Initial Catalog=MTWorkHRDB;Persist Security Info=False;User ID=MTWorkHR;Password=MTWork@12345;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
+    "LocalConnectionString": "Server=.;Database=MTWorkHRDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true;Integrated Security=True;Encrypt=False",
+    "BlobConnectionString": "DefaultEndpointsProtocol=https;AccountName=mtworkhrstorage;AccountKey=8EfjO3+4jHmf6QSnW5PCFDWry8oXSAM4pGtlIviImd5yCo6lxWDUpnzfT6ppHJqhKztuGU9IL4Ai+ASt16oHZA==;EndpointSuffix=core.windows.net"
+
     // "HRIdentityDB": "Server=localhost;Database=HRIdentityDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true"
     //Data Source=.;Initial Catalog=CBQ_VIVR;Integrated Security=True;Encrypt=False
   },

+ 1 - 1
MTWorkHR.API/appsettings.json

@@ -7,7 +7,7 @@
   },
   "ConnectionStrings": {
     "MTWorkHRConnectionString": "Server=tcp:mtworksqlserver.database.windows.net,1433;Initial Catalog=MTWorkHRDB;Persist Security Info=False;User ID=MTWorkHR;Password=MTWork@12345;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
-    "LocalConnectionString": "Server=.;Database=MTWorkHRDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true;Integrated Security=True;Encrypt=False",
+    //"LocalConnectionString": "Server=.;Database=MTWorkHRDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true;Integrated Security=True;Encrypt=False",
     "BlobConnectionString": "DefaultEndpointsProtocol=https;AccountName=mtworkhrstorage;AccountKey=8EfjO3+4jHmf6QSnW5PCFDWry8oXSAM4pGtlIviImd5yCo6lxWDUpnzfT6ppHJqhKztuGU9IL4Ai+ASt16oHZA==;EndpointSuffix=core.windows.net"
     // "HRIdentityDB": "Server=localhost;Database=HRIdentityDB;User=sa;Password=p@ssw0rd;MultipleActiveResultSets=true"
     //Data Source=.;Initial Catalog=CBQ_VIVR;Integrated Security=True;Encrypt=False

+ 2 - 2
MTWorkHR.Application/Services/User/UserService.cs

@@ -319,7 +319,7 @@ namespace MTWorkHR.Application.Services
                 user.UserType = (int)UserTypeEnum.Employee;//default if not selected
             }
             _unitOfWork.BeginTran();
-
+            user.CreateDate = DateTime.Now;
             //saving user
             var result = await _userManager.CreateAsync(user, input.Password);
             if (!result.Succeeded)
@@ -490,7 +490,7 @@ namespace MTWorkHR.Application.Services
                 MapperObject.Mapper.Map(input, entity);
 
                 _unitOfWork.BeginTran();
-
+                entity.UpdateDate = DateTime.Now;
                 //saving user
                 var result = await _userManager.UpdateAsync(entity);
                 if (!result.Succeeded)

+ 26 - 0
MTWorkHR.Core/Entities/Chat/ChatAttachment.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.VisualBasic.FileIO;
+using MTWorkHR.Core.Entities.Base;
+
+namespace MTWorkHR.Core.Entities
+{
+    public class ChatAttachment: AuditEntity
+    {
+
+        public long ChatMessageId{ get; set; }
+        [ForeignKey("ChatMessageId")]
+        public ChatMessage ChatMessage { get; set; }
+        [MaxLength(250)]
+        public string? FileName { get; set; }
+        public string FilePath { get; set; }
+        public string FileType { get; set; }
+        public string? ContentType { get; set; }
+
+    }
+}

+ 25 - 0
MTWorkHR.Core/Entities/Chat/ChatMessage.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Core.Entities.Base;
+
+namespace MTWorkHR.Core.Entities
+{
+    public class ChatMessage : AuditEntity
+    {
+
+        public string SenderId{ get; set; }
+        public string SenderName { get; set; }
+        public string ReceiverId { get; set; }
+        public string ReceiverName { get; set; }
+        public string Content{ get; set; }
+        public bool IsSeen { get; set; }
+        public List<ChatAttachment>? ChatAttachments { get; set; }
+
+
+    }
+}

+ 16 - 0
MTWorkHR.Core/IRepositories/Chat/IChatMessageRepository.cs

@@ -0,0 +1,16 @@
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IRepositories.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Core.IRepositories
+{
+    public interface IChatMessageRepository : IRepository<ChatMessage>
+    {
+        Task<ChatMessage> GetByIdWithAllChildren(long id);
+        Task<Tuple<IQueryable<ChatMessage>, int>> GetAllWithChildrenAsync();
+    }
+}

+ 3 - 0
MTWorkHR.Core/IUnitOfWork/IUnitOfWork.cs

@@ -34,6 +34,9 @@ namespace MTWorkHR.Core.UnitOfWork
         ICityRepository City{ get; }
         IQualificationRepository Qualification { get; }
         ILoginOTPRepository LoginOTP { get; }
+
+        IChatMessageRepository ChatMessage { get; }
+
         Task<int> CompleteAsync();
 
         void BeginTran();

+ 1 - 0
MTWorkHR.Infrastructure/DBContext/HRDataContext.cs

@@ -41,6 +41,7 @@ namespace MTWorkHR.Infrastructure.DBContext
         public DbSet<LeaveType> LeaveTypes { get; set; }
         public DbSet<OrderAllocation> OrderAllocations { get; set; }
         public DbSet<OrderRequest> OrderRequests { get; set; }
+        public DbSet<ChatMessage> ChatMessages { get; set; }
         //-------------------Lookups---------------------------
         public DbSet<CountryLookup> CountryLookups { get; set; }
         public DbSet<Qualification> Qualifications { get; set; }

+ 2 - 0
MTWorkHR.Infrastructure/Entities/ApplicationUser.cs

@@ -49,6 +49,8 @@ namespace MTWorkHR.Infrastructure.Entities
 
 
         public string? CreateUser { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate{ get; set; }
         public string? UpdateUser { get; set; }
 
         public bool IsStopped { get; set; }

+ 1 - 0
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -82,6 +82,7 @@ namespace MTWorkHR.Infrastructure
             services.AddScoped(typeof(ILoginOTPRepository), typeof(LoginOTPRepository));
             services.AddScoped(typeof(ICityRepository), typeof(CityRepository));
             services.AddScoped(typeof(IProjectTeamRepository), typeof(ProjectTeamRepository));
+            services.AddScoped(typeof(IChatMessageRepository), typeof(ChatMessageRepository));
 
 
 

File diff suppressed because it is too large
+ 3624 - 0
MTWorkHR.Infrastructure/Migrations/20240916101932_chatTbls.Designer.cs


+ 113 - 0
MTWorkHR.Infrastructure/Migrations/20240916101932_chatTbls.cs

@@ -0,0 +1,113 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class chatTbls : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AddColumn<DateTime>(
+                name: "CreateDate",
+                table: "AspNetUsers",
+                type: "datetime2",
+                nullable: true);
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "UpdateDate",
+                table: "AspNetUsers",
+                type: "datetime2",
+                nullable: true);
+
+            migrationBuilder.CreateTable(
+                name: "ChatMessages",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    SenderId = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    ReceiverId = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    ReceiverName = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    Content = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    IsSeen = table.Column<bool>(type: "bit", nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_ChatMessages", x => x.Id);
+                });
+
+            migrationBuilder.CreateTable(
+                name: "ChatAttachment",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    ChatMessageId = table.Column<long>(type: "bigint", nullable: false),
+                    FileName = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: true),
+                    FilePath = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    FileType = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    ContentType = table.Column<string>(type: "nvarchar(max)", nullable: true)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_ChatAttachment", x => x.Id);
+                    table.ForeignKey(
+                        name: "FK_ChatAttachment_ChatMessages_ChatMessageId",
+                        column: x => x.ChatMessageId,
+                        principalTable: "ChatMessages",
+                        principalColumn: "Id",
+                        onDelete: ReferentialAction.Cascade);
+                });
+
+            migrationBuilder.UpdateData(
+                table: "AspNetUsers",
+                keyColumn: "Id",
+                keyValue: "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
+                columns: new[] { "CreateDate", "UpdateDate" },
+                values: new object[] { null, null });
+
+            migrationBuilder.UpdateData(
+                table: "AspNetUsers",
+                keyColumn: "Id",
+                keyValue: "AL5B3B92-2311-48F8-9DEC-F9FAEF1F21UB",
+                columns: new[] { "CreateDate", "UpdateDate" },
+                values: new object[] { null, null });
+
+            migrationBuilder.CreateIndex(
+                name: "IX_ChatAttachment_ChatMessageId",
+                table: "ChatAttachment",
+                column: "ChatMessageId");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropTable(
+                name: "ChatAttachment");
+
+            migrationBuilder.DropTable(
+                name: "ChatMessages");
+
+            migrationBuilder.DropColumn(
+                name: "CreateDate",
+                table: "AspNetUsers");
+
+            migrationBuilder.DropColumn(
+                name: "UpdateDate",
+                table: "AspNetUsers");
+        }
+    }
+}

+ 168 - 39
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
@@ -314,6 +314,113 @@ namespace MTWorkHR.Infrastructure.Migrations
                         });
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.ChatAttachment", b =>
+                {
+                    b.Property<long>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("bigint")
+                        .HasColumnOrder(0);
+
+                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
+
+                    b.Property<long>("ChatMessageId")
+                        .HasColumnType("bigint");
+
+                    b.Property<string>("ContentType")
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime>("CreateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(3);
+
+                    b.Property<string>("CreateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(1);
+
+                    b.Property<string>("FileName")
+                        .HasMaxLength(250)
+                        .HasColumnType("nvarchar(250)");
+
+                    b.Property<string>("FilePath")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("FileType")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime?>("UpdateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(4);
+
+                    b.Property<string>("UpdateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(2);
+
+                    b.HasKey("Id");
+
+                    b.HasIndex("ChatMessageId");
+
+                    b.ToTable("ChatAttachment");
+                });
+
+            modelBuilder.Entity("MTWorkHR.Core.Entities.ChatMessage", b =>
+                {
+                    b.Property<long>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("bigint")
+                        .HasColumnOrder(0);
+
+                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
+
+                    b.Property<string>("Content")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime>("CreateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(3);
+
+                    b.Property<string>("CreateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(1);
+
+                    b.Property<bool>("IsSeen")
+                        .HasColumnType("bit");
+
+                    b.Property<string>("ReceiverId")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("ReceiverName")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("SenderId")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("SenderName")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime?>("UpdateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(4);
+
+                    b.Property<string>("UpdateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(2);
+
+                    b.HasKey("Id");
+
+                    b.ToTable("ChatMessages");
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.City", b =>
                 {
                     b.Property<long>("Id")
@@ -348,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 =>
@@ -404,7 +511,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Companies", (string)null);
+                    b.ToTable("Companies");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.CountryLookup", b =>
@@ -436,7 +543,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("CountryLookups", (string)null);
+                    b.ToTable("CountryLookups");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.FileLog", b =>
@@ -494,7 +601,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("FileLogs", (string)null);
+                    b.ToTable("FileLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Industry", b =>
@@ -518,7 +625,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Industries", (string)null);
+                    b.ToTable("Industries");
 
                     b.HasData(
                         new
@@ -844,7 +951,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("JobTitles", (string)null);
+                    b.ToTable("JobTitles");
 
                     b.HasData(
                         new
@@ -1015,7 +1122,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("LeaveTypes", (string)null);
+                    b.ToTable("LeaveTypes");
 
                     b.HasData(
                         new
@@ -1080,7 +1187,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("LoginOTPs", (string)null);
+                    b.ToTable("LoginOTPs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Meeting", b =>
@@ -1157,7 +1264,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Meetings", (string)null);
+                    b.ToTable("Meetings");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingLog", b =>
@@ -1215,7 +1322,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("MeetingLogs", (string)null);
+                    b.ToTable("MeetingLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.MeetingUser", b =>
@@ -1260,7 +1367,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("MeetingId");
 
-                    b.ToTable("MeetingUser", (string)null);
+                    b.ToTable("MeetingUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.OrderAllocation", b =>
@@ -1317,7 +1424,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("OrderTypeId");
 
-                    b.ToTable("OrderAllocations", (string)null);
+                    b.ToTable("OrderAllocations");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.OrderType", b =>
@@ -1342,7 +1449,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("OrderTypes", (string)null);
+                    b.ToTable("OrderTypes");
 
                     b.HasData(
                         new
@@ -1411,7 +1518,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Permissions", (string)null);
+                    b.ToTable("Permissions");
 
                     b.HasData(
                         new
@@ -1697,7 +1804,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Projects", (string)null);
+                    b.ToTable("Projects");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.ProjectTeam", b =>
@@ -1741,7 +1848,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("ProjectId");
 
-                    b.ToTable("ProjectTeam", (string)null);
+                    b.ToTable("ProjectTeam");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Qualification", b =>
@@ -1765,7 +1872,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Qualifications", (string)null);
+                    b.ToTable("Qualifications");
 
                     b.HasData(
                         new
@@ -1843,7 +1950,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("RoleLogs", (string)null);
+                    b.ToTable("RoleLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.SettingLog", b =>
@@ -1901,7 +2008,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("SettingLogs", (string)null);
+                    b.ToTable("SettingLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TaskUser", b =>
@@ -1945,7 +2052,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("TaskUser", (string)null);
+                    b.ToTable("TaskUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.Team", b =>
@@ -2001,7 +2108,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("CompanyId");
 
-                    b.ToTable("Teams", (string)null);
+                    b.ToTable("Teams");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamLog", b =>
@@ -2059,7 +2166,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("TeamLogs", (string)null);
+                    b.ToTable("TeamLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamUser", b =>
@@ -2107,7 +2214,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TeamId");
 
-                    b.ToTable("TeamUser", (string)null);
+                    b.ToTable("TeamUser");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.University", b =>
@@ -2131,7 +2238,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("Universities", (string)null);
+                    b.ToTable("Universities");
 
                     b.HasData(
                         new
@@ -2235,7 +2342,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("OrderTypeId");
 
-                    b.ToTable("OrderRequests", (string)null);
+                    b.ToTable("OrderRequests");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserLog", b =>
@@ -2293,7 +2400,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserLogs", (string)null);
+                    b.ToTable("UserLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTask", b =>
@@ -2367,7 +2474,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("StatusId");
 
-                    b.ToTable("UserTasks", (string)null);
+                    b.ToTable("UserTasks");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskAttachment", b =>
@@ -2427,7 +2534,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("UserTaskAttachments", (string)null);
+                    b.ToTable("UserTaskAttachments");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskHistory", b =>
@@ -2479,7 +2586,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("TaskId");
 
-                    b.ToTable("UserTaskHistories", (string)null);
+                    b.ToTable("UserTaskHistories");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskLog", b =>
@@ -2537,7 +2644,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserTaskLogs", (string)null);
+                    b.ToTable("UserTaskLogs");
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTaskStatus", b =>
@@ -2561,7 +2668,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasKey("Id");
 
-                    b.ToTable("UserTaskStatuses", (string)null);
+                    b.ToTable("UserTaskStatuses");
 
                     b.HasData(
                         new
@@ -2685,6 +2792,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<long?>("CountryId")
                         .HasColumnType("bigint");
 
+                    b.Property<DateTime?>("CreateDate")
+                        .HasColumnType("datetime2");
+
                     b.Property<string>("CreateUser")
                         .HasColumnType("nvarchar(max)");
 
@@ -2782,6 +2892,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<long?>("UniversityId")
                         .HasColumnType("bigint");
 
+                    b.Property<DateTime?>("UpdateDate")
+                        .HasColumnType("datetime2");
+
                     b.Property<string>("UpdateUser")
                         .HasColumnType("nvarchar(max)");
 
@@ -2901,7 +3014,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("RoleId");
 
-                    b.ToTable("RolePermissions", (string)null);
+                    b.ToTable("RolePermissions");
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.UserAddress", b =>
@@ -2956,7 +3069,7 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.HasIndex("UserId")
                         .IsUnique();
 
-                    b.ToTable("UserAddress", (string)null);
+                    b.ToTable("UserAddress");
                 });
 
             modelBuilder.Entity("MTWorkHR.Infrastructure.Entities.UserAttachment", b =>
@@ -3019,7 +3132,7 @@ namespace MTWorkHR.Infrastructure.Migrations
 
                     b.HasIndex("UserId");
 
-                    b.ToTable("UserAttachments", (string)null);
+                    b.ToTable("UserAttachments");
                 });
 
             modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
@@ -3155,6 +3268,17 @@ namespace MTWorkHR.Infrastructure.Migrations
                         .IsRequired();
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.ChatAttachment", b =>
+                {
+                    b.HasOne("MTWorkHR.Core.Entities.ChatMessage", "ChatMessage")
+                        .WithMany("ChatAttachments")
+                        .HasForeignKey("ChatMessageId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
+
+                    b.Navigation("ChatMessage");
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.City", b =>
                 {
                     b.HasOne("MTWorkHR.Core.Entities.CountryLookup", "Country")
@@ -3450,6 +3574,11 @@ namespace MTWorkHR.Infrastructure.Migrations
                         .IsRequired();
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.ChatMessage", b =>
+                {
+                    b.Navigation("ChatAttachments");
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.Meeting", b =>
                 {
                     b.Navigation("MeetingUsers");

+ 33 - 0
MTWorkHR.Infrastructure/Repositories/Chat/ChatMessageRepository.cs

@@ -0,0 +1,33 @@
+using Microsoft.EntityFrameworkCore;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IDto;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Infrastructure.DBContext;
+using MTWorkHR.Core.IRepositories;
+
+namespace MTWorkHR.Infrastructure.Repositories
+{
+    public class ChatMessageRepository : Repository<ChatMessage>, IChatMessageRepository
+    {
+        private readonly DbSet<ChatMessage> dbSet;
+
+        public ChatMessageRepository(HRDataContext context) : base(context)
+        {
+            dbSet = context.Set<ChatMessage>();
+        }
+        
+        public async Task<ChatMessage> GetByIdWithAllChildren(long id)
+        {
+            return await dbSet
+                .Include(x => x.ChatAttachments)
+                .FirstOrDefaultAsync(x => x.Id == id);
+        }
+        public async Task<Tuple<IQueryable<ChatMessage>, int>> GetAllWithChildrenAsync()
+        {
+            var query = dbSet.Include(x => x.ChatAttachments).AsQueryable();
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<ChatMessage>, int>(query, total);
+        }
+    }
+}

+ 4 - 3
MTWorkHR.Infrastructure/UnitOfWork/UnitOfWork.cs

@@ -38,6 +38,7 @@ namespace MTWorkHR.Infrastructure.UnitOfWorks
         public IUniversityRepository University { get; }
         public ILoginOTPRepository LoginOTP { get; }
         public ICityRepository City { get; }
+        public IChatMessageRepository ChatMessage { get; }
 
         public UnitOfWork(HRDataContext _context
             , IPermissionRepository permission
@@ -63,9 +64,8 @@ namespace MTWorkHR.Infrastructure.UnitOfWorks
             , ICityRepository city
             , ITeamUserRepository teamUser
             , IMeetingUserRepository meetingUser
-,
-IProjectTeamRepository projectTeam
-
+            , IProjectTeamRepository projectTeam
+            , IChatMessageRepository chatMessage
             )
         {
             context = _context;
@@ -93,6 +93,7 @@ IProjectTeamRepository projectTeam
             TeamUser = teamUser;
             MeetingUser = meetingUser;
             ProjectTeam = projectTeam;
+            ChatMessage = chatMessage;
         }
 
         public async Task<int> CompleteAsync()