From dee6bc7bef967554ae1ecce60782fd00b309687b Mon Sep 17 00:00:00 2001 From: alireza Date: Thu, 11 Jun 2026 19:42:58 +0330 Subject: [PATCH] feat: add person name and insert time to announcement DTO - Added PersonName property to AnnouncementDto to display person's full name - Added lookup logic to fetch person names from Persons table based on phone numbers - Added InsertTime shadow property retrieval from EF Core to display creation date - Updated model snapshot with new shadow properties (InsertTime, IsRemoved, RemoveTime, UpdateTime) for Chat entity --- .../Services/AnnouncementService.cs | 38 +++++++++++++++---- .../ComplexDBContextModelSnapshot.cs | 36 +++++++++++++----- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/Complex.Application/Services/AnnouncementService.cs b/Complex.Application/Services/AnnouncementService.cs index 15dee36..8ed3f1d 100644 --- a/Complex.Application/Services/AnnouncementService.cs +++ b/Complex.Application/Services/AnnouncementService.cs @@ -33,14 +33,37 @@ namespace Complex.Application.Services.Announcement .Take(pageSize) .ToList(); - var result = chats.Select(c => new AnnouncementDto + // Get unique phone numbers to look up person names + var phoneNumbers = chats + .Select(c => c.PersonMobileNumber) + .Where(p => p != null) + .Distinct() + .ToList(); + + var personNames = _complexDBContext.Persons + .Where(p => phoneNumbers.Contains(p.Id)) + .ToDictionary(p => p.Id, p => $"{p.FirstName} {p.LastName}".Trim()); + + var result = chats.Select(c => { - Id = c.Id, - ComplexId = c.ComplexId, - PersonMobileNumber = c.PersonMobileNumber, - Body = c.Body, - ChatTypeId = c.ChatTypeId, - InsertTime = null // InsertTime is set by Auditable attribute in SaveChanges, not a property on Chat entity + personNames.TryGetValue(c.PersonMobileNumber, out var personName); + + // Read InsertTime from EF Core shadow property + var insertTimeEntry = _complexDBContext.Entry(c).Property("InsertTime"); + var insertTime = insertTimeEntry?.CurrentValue as DateTime?; + + return new AnnouncementDto + { + Id = c.Id, + ComplexId = c.ComplexId, + PersonMobileNumber = c.PersonMobileNumber, + PersonName = personName, + Body = c.Body, + ChatTypeId = c.ChatTypeId, + InsertTime = insertTime.HasValue + ? insertTime.Value.ToString("yyyy/MM/dd HH:mm") + : null + }; }).ToList(); return new ResultDto> @@ -78,6 +101,7 @@ namespace Complex.Application.Services.Announcement public long Id { get; set; } public Guid ComplexId { get; set; } public string? PersonMobileNumber { get; set; } + public string? PersonName { get; set; } public string? Body { get; set; } public byte? ChatTypeId { get; set; } public string? InsertTime { get; set; } diff --git a/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs b/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs index b176ef1..8204059 100644 --- a/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs +++ b/Complex.Infrastructure/Migrations/ComplexDBContextModelSnapshot.cs @@ -60,10 +60,26 @@ namespace Complex.Infrastructure.Migrations b.Property("ComplexId") .HasColumnType("uniqueidentifier"); + b.Property("InsertTime") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2") + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 678, DateTimeKind.Local).AddTicks(4132)); + + b.Property("IsRemoved") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + b.Property("PersonMobileNumber") .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("RemoveTime") + .HasColumnType("datetime2"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + b.HasKey("Id"); b.ToTable("Chats"); @@ -111,7 +127,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 623, DateTimeKind.Local).AddTicks(7632)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 678, DateTimeKind.Local).AddTicks(7208)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -170,7 +186,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(2426)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 678, DateTimeKind.Local).AddTicks(9914)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -246,7 +262,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(5016)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 679, DateTimeKind.Local).AddTicks(795)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -298,7 +314,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(7249)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 679, DateTimeKind.Local).AddTicks(1849)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -338,7 +354,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 624, DateTimeKind.Local).AddTicks(9858)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 679, DateTimeKind.Local).AddTicks(3528)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -386,7 +402,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(1728)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 679, DateTimeKind.Local).AddTicks(5645)); b.Property("IsActive") .HasColumnType("bit"); @@ -500,7 +516,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(3921)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 679, DateTimeKind.Local).AddTicks(7492)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -571,7 +587,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(7151)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 679, DateTimeKind.Local).AddTicks(9506)); b.Property("IsActive") .HasColumnType("bit"); @@ -642,7 +658,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 625, DateTimeKind.Local).AddTicks(9764)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 680, DateTimeKind.Local).AddTicks(1537)); b.Property("IsRemoved") .ValueGeneratedOnAdd() @@ -685,7 +701,7 @@ namespace Complex.Infrastructure.Migrations b.Property("InsertTime") .ValueGeneratedOnAdd() .HasColumnType("datetime2") - .HasDefaultValue(new DateTime(2026, 6, 9, 2, 28, 45, 626, DateTimeKind.Local).AddTicks(1646)); + .HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 680, DateTimeKind.Local).AddTicks(2670)); b.Property("IsRemoved") .ValueGeneratedOnAdd()