From 948457a83f221f100be54ae7214e91a548151cb8 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 17 May 2025 16:44:24 +0530 Subject: [PATCH 1/3] Added an API to Update existing Contact-note --- .../Controllers/DirectoryController.cs | 60 +++++++++---------- Marco.Pms.Services/Helpers/DirectoryHelper.cs | 38 ++++++++++++ 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/Marco.Pms.Services/Controllers/DirectoryController.cs b/Marco.Pms.Services/Controllers/DirectoryController.cs index dd3785e..a901e38 100644 --- a/Marco.Pms.Services/Controllers/DirectoryController.cs +++ b/Marco.Pms.Services/Controllers/DirectoryController.cs @@ -104,20 +104,20 @@ namespace Marco.Pms.Services.Controllers [HttpPost("note")] public async Task CreateContactNote([FromBody] CreateContactNoteDto noteDto) { - return Ok(); - //var response = await _directoryHelper.CreateContactNote(noteDto); - //if (response.StatusCode == 200) - //{ - //return Ok(response); - //} - //else if (response.StatusCode == 404) - //{ - // return NotFound(response); - //} - //else - //{ - // return BadRequest(response); - //} + + var response = await _directoryHelper.CreateContactNote(noteDto); + if (response.StatusCode == 200) + { + return Ok(response); + } + else if (response.StatusCode == 404) + { + return NotFound(response); + } + else + { + return BadRequest(response); + } } [HttpGet("note/{ContactId}")] @@ -141,28 +141,26 @@ namespace Marco.Pms.Services.Controllers [HttpPut("note/{id}")] public async Task UpdateContactNote(Guid id, [FromBody] UpdateContactNoteDto noteDto) { - return Ok(); - //var response = await _directoryHelper.UpdateContactNote(id, noteDto); - //if (response.StatusCode == 200) - //{ - // return Ok(response); - //} - //else if (response.StatusCode == 404) - //{ - // return NotFound(response); - //} - //else - //{ - // return BadRequest(response); - //} + var response = await _directoryHelper.UpdateContactNote(id, noteDto); + if (response.StatusCode == 200) + { + return Ok(response); + } + else if (response.StatusCode == 404) + { + return NotFound(response); + } + else + { + return BadRequest(response); + } } [HttpDelete("note/{id}")] public async Task DeleteContactNote(Guid id) { - return Ok(); - //var response = await _directoryHelper.DeleteContactNote(id); - //return Ok(response); + var response = await _directoryHelper.DeleteContactNote(id); + return Ok(response); } // -------------------------------- Bucket -------------------------------- diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index b68a854..a185a1d 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -647,6 +647,44 @@ namespace Marco.Pms.Services.Helpers return ApiResponse.ErrorResponse("Contact not found", "Contact not found", 404); } + public async Task> 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.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.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.ErrorResponse("Contact not found", "Contact not found", 404); + } + _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); + return ApiResponse.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); + } + // -------------------------------- Bucket -------------------------------- public async Task> GetBucketList() -- 2.43.0 From 651785720f27e70b31579bf2f9a1b5c351793a36 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 17 May 2025 16:45:10 +0530 Subject: [PATCH 2/3] Added an API to suspend a n existing Contact-note --- Marco.Pms.Services/Helpers/DirectoryHelper.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index a185a1d..9861a15 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -684,6 +684,28 @@ namespace Marco.Pms.Services.Helpers _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); return ApiResponse.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); } + public async Task> DeleteContactNote(Guid id) + { + Guid tenentId = _userHelper.GetTenantId(); + var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + + ContactNote? note = await _context.ContactNotes.FirstOrDefaultAsync(n => n.Id == id && n.TenantId == tenentId); + if (note != null) + { + note.IsActive = false; + _context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog + { + RefereanceId = id, + UpdatedById = LoggedInEmployee.Id, + UpdateAt = DateTime.UtcNow + }); + await _context.SaveChangesAsync(); + _logger.LogInfo("Employee {EmployeeId} deleted note {NoteId}", LoggedInEmployee.Id, id); + } + + _logger.LogWarning("Employee {EmployeeId} tries to delete contact note {NoteId} but not found in database", LoggedInEmployee.Id, id); + return ApiResponse.SuccessResponse(new { }, "Note deleted successfully", 200); + } // -------------------------------- Bucket -------------------------------- -- 2.43.0 From 077af5ac598e95751ca2d590ad8731ca7f151ea7 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 17 May 2025 16:45:43 +0530 Subject: [PATCH 3/3] Added an API to add a note to specific contact --- Marco.Pms.Services/Helpers/DirectoryHelper.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Marco.Pms.Services/Helpers/DirectoryHelper.cs b/Marco.Pms.Services/Helpers/DirectoryHelper.cs index 9861a15..ebaeb4e 100644 --- a/Marco.Pms.Services/Helpers/DirectoryHelper.cs +++ b/Marco.Pms.Services/Helpers/DirectoryHelper.cs @@ -646,7 +646,28 @@ namespace Marco.Pms.Services.Helpers _logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to fetch a list notes from contact with ID {ContactId}, but the contact was not found in the database.", LoggedInEmployee.Id, id); return ApiResponse.ErrorResponse("Contact not found", "Contact not found", 404); } - + public async Task> CreateContactNote(CreateContactNoteDto noteDto) + { + Guid tenantId = _userHelper.GetTenantId(); + var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync(); + if (noteDto != null) + { + Contact? contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == noteDto.ContactId && c.IsActive && c.TenantId == tenantId); + if (contact != null) + { + ContactNote note = noteDto.ToContactNoteFromCreateContactNoteDto(tenantId, LoggedInEmployee.Id); + _context.ContactNotes.Add(note); + await _context.SaveChangesAsync(); + ContactNoteVM noteVM = note.ToContactNoteVMFromContactNote(); + _logger.LogInfo("Employee {EmployeeId} Added note at contact {ContactId}", LoggedInEmployee.Id, contact.Id); + return ApiResponse.SuccessResponse(noteVM, "Note added successfully", 200); + } + _logger.LogWarning("Employee with ID {LoggedInEmployeeId} attempted to add a note to contact with ID {ContactId}, but the contact was not found in the database.", LoggedInEmployee.Id, noteDto.ContactId); + return ApiResponse.ErrorResponse("Contact not found", "Contact not found", 404); + } + _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); + return ApiResponse.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); + } public async Task> UpdateContactNote(Guid id, UpdateContactNoteDto noteDto) { Guid tenantId = _userHelper.GetTenantId(); -- 2.43.0