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
This commit is contained in:
2026-06-11 19:42:58 +03:30
parent 861a98668e
commit dee6bc7bef
2 changed files with 57 additions and 17 deletions

View File

@@ -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<List<AnnouncementDto>>
@@ -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; }

View File

@@ -60,10 +60,26 @@ namespace Complex.Infrastructure.Migrations
b.Property<Guid>("ComplexId")
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("InsertTime")
.ValueGeneratedOnAdd()
.HasColumnType("datetime2")
.HasDefaultValue(new DateTime(2026, 6, 11, 19, 41, 56, 678, DateTimeKind.Local).AddTicks(4132));
b.Property<bool>("IsRemoved")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("PersonMobileNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("RemoveTime")
.HasColumnType("datetime2");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Chats");
@@ -111,7 +127,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -170,7 +186,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -246,7 +262,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -298,7 +314,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -338,7 +354,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -386,7 +402,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsActive")
.HasColumnType("bit");
@@ -500,7 +516,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -571,7 +587,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsActive")
.HasColumnType("bit");
@@ -642,7 +658,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()
@@ -685,7 +701,7 @@ namespace Complex.Infrastructure.Migrations
b.Property<DateTime>("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<bool>("IsRemoved")
.ValueGeneratedOnAdd()