Added an API to Update existing Contact-note
This commit is contained in:
parent
75cb4557e4
commit
dff77aa22f
@ -939,6 +939,44 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<ApiResponse<object>> UpdateContactNote(Guid id, UpdateContactNoteDto noteDto)
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
if (noteDto != null && id == noteDto.Id)
|
||||||
|
{
|
||||||
|
Contact? contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == noteDto.ContactId && c.IsActive && c.TenantId == tenantId);
|
||||||
|
if (contact != null)
|
||||||
|
{
|
||||||
|
ContactNote? contactNote = await _context.ContactNotes.FirstOrDefaultAsync(n => n.Id == noteDto.Id && n.ContactId == contact.Id && n.IsActive);
|
||||||
|
if (contactNote != null)
|
||||||
|
{
|
||||||
|
contactNote.Note = noteDto.Note;
|
||||||
|
|
||||||
|
_context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog
|
||||||
|
{
|
||||||
|
RefereanceId = id,
|
||||||
|
UpdatedById = LoggedInEmployee.Id,
|
||||||
|
UpdateAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
ContactNoteVM noteVM = contactNote.ToContactNoteVMFromContactNote();
|
||||||
|
|
||||||
|
|
||||||
|
_logger.LogInfo("Employee {EmployeeId} updated note {NoteId} at contact {ContactId}", LoggedInEmployee.Id, noteVM.Id, contact.Id);
|
||||||
|
return ApiResponse<object>.SuccessResponse(noteVM, "Note updated successfully", 200);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to update a note {NoteId} to contact with ID {ContactId}, but the Note was not found in the database.", LoggedInEmployee.Id, noteDto.Id, noteDto.ContactId);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Note not found", "Note not found", 404);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to update a note {NoteId} to contact with ID {ContactId}, but the contact was not found in the database.", LoggedInEmployee.Id, noteDto.Id, noteDto.ContactId);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------- Bucket --------------------------------
|
// -------------------------------- Bucket --------------------------------
|
||||||
|
|
||||||
public async Task<ApiResponse<object>> GetBucketList()
|
public async Task<ApiResponse<object>> GetBucketList()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user