Sending last updatedBy and updatedAt when sending list of notes
This commit is contained in:
parent
7dc80ec006
commit
af9e06cd98
@ -2228,11 +2228,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<DirectoryUpdateLog>? updateLogs = await _context.DirectoryUpdateLogs.Include(l => l.Employee).Where(l => noteIds.Contains(l.RefereanceId)).ToListAsync();
|
||||
List<ContactNoteVM>? noteVMs = new List<ContactNoteVM>();
|
||||
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<object>.SuccessResponse(noteVMs, $"{noteVMs.Count} contact-notes record fetched successfully", 200);
|
||||
|
Loading…
x
Reference in New Issue
Block a user