Sending last updatedBy and updatedAt when sending list of notes

This commit is contained in:
ashutosh.nehete 2025-05-28 15:00:56 +05:30
parent 2552e4b83d
commit 55e8ace430

View File

@ -909,11 +909,25 @@ namespace Marco.Pms.Services.Helpers
{ {
notes = await _context.ContactNotes.Where(n => n.ContactId == contact.Id && n.TenantId == tenantId).ToListAsync(); notes = await _context.ContactNotes.Where(n => n.ContactId == contact.Id && n.TenantId == tenantId).ToListAsync();
} }
var noteIds = notes.Select(n => n.Id).ToList();
List<DirectoryUpdateLog>? updateLogs = await _context.DirectoryUpdateLogs.Include(l => l.Employee).Where(l => noteIds.Contains(l.RefereanceId)).ToListAsync();
List<ContactNoteVM>? noteVMs = new List<ContactNoteVM>(); List<ContactNoteVM>? noteVMs = new List<ContactNoteVM>();
foreach (var note in notes) foreach (var note in notes)
{ {
ContactNoteVM noteVM = note.ToContactNoteVMFromContactNote(); 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); noteVMs.Add(noteVM);
} }
_logger.LogInfo("{count} contact-notes record from contact {ContactId} fetched by Employee {EmployeeId}", noteVMs.Count, id, LoggedInEmployee.Id); _logger.LogInfo("{count} contact-notes record from contact {ContactId} fetched by Employee {EmployeeId}", noteVMs.Count, id, LoggedInEmployee.Id);
return ApiResponse<object>.SuccessResponse(noteVMs, $"{noteVMs.Count} contact-notes record fetched successfully", 200); return ApiResponse<object>.SuccessResponse(noteVMs, $"{noteVMs.Count} contact-notes record fetched successfully", 200);