From 55e8ace430fca48de8ce488aad7159ca204ad9e9 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Wed, 28 May 2025 15:00:56 +0530 Subject: [PATCH] Sending last updatedBy and updatedAt when sending list of notes --- Marco.Pms.Services/Helpers/DirectoryHelper.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index 87d3b8e..b71c5fc 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -909,11 +909,25 @@ namespace Marco.Pms.Services.Helpers { notes = await _context.ContactNotes.Where(n => n.ContactId == contact.Id && n.TenantId == tenantId).ToListAsync(); } + var noteIds = notes.Select(n => n.Id).ToList(); + List? updateLogs = await _context.DirectoryUpdateLogs.Include(l => l.Employee).Where(l => noteIds.Contains(l.RefereanceId)).ToListAsync(); List? noteVMs = new List(); foreach (var note in notes) { ContactNoteVM noteVM = note.ToContactNoteVMFromContactNote(); + DirectoryUpdateLog? updateLog = updateLogs.Where(l => l.RefereanceId == note.Id).OrderByDescending(l => l.UpdateAt).FirstOrDefault(); + if (updateLog != null) + { + noteVM.UpdatedAt = updateLog.UpdateAt; + noteVM.UpdatedBy = updateLog.Employee != null ? updateLog.Employee.ToBasicEmployeeVMFromEmployee() : null; + } + else + { + noteVM.UpdatedAt = note.CreatedAt; + noteVM.UpdatedBy = note.Createdby != null ? note.Createdby.ToBasicEmployeeVMFromEmployee() : null; + } noteVMs.Add(noteVM); + } _logger.LogInfo("{count} contact-notes record from contact {ContactId} fetched by Employee {EmployeeId}", noteVMs.Count, id, LoggedInEmployee.Id); return ApiResponse.SuccessResponse(noteVMs, $"{noteVMs.Count} contact-notes record fetched successfully", 200);