Compare commits
4 Commits
824dd45d4c
...
c0336513c4
Author | SHA1 | Date | |
---|---|---|---|
c0336513c4 | |||
077af5ac59 | |||
651785720f | |||
948457a83f |
@ -104,20 +104,20 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
[HttpPost("note")]
|
[HttpPost("note")]
|
||||||
public async Task<IActionResult> CreateContactNote([FromBody] CreateContactNoteDto noteDto)
|
public async Task<IActionResult> CreateContactNote([FromBody] CreateContactNoteDto noteDto)
|
||||||
{
|
{
|
||||||
return Ok();
|
|
||||||
//var response = await _directoryHelper.CreateContactNote(noteDto);
|
var response = await _directoryHelper.CreateContactNote(noteDto);
|
||||||
//if (response.StatusCode == 200)
|
if (response.StatusCode == 200)
|
||||||
//{
|
{
|
||||||
//return Ok(response);
|
return Ok(response);
|
||||||
//}
|
}
|
||||||
//else if (response.StatusCode == 404)
|
else if (response.StatusCode == 404)
|
||||||
//{
|
{
|
||||||
// return NotFound(response);
|
return NotFound(response);
|
||||||
//}
|
}
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// return BadRequest(response);
|
return BadRequest(response);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("note/{ContactId}")]
|
[HttpGet("note/{ContactId}")]
|
||||||
@ -141,28 +141,26 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
[HttpPut("note/{id}")]
|
[HttpPut("note/{id}")]
|
||||||
public async Task<IActionResult> UpdateContactNote(Guid id, [FromBody] UpdateContactNoteDto noteDto)
|
public async Task<IActionResult> UpdateContactNote(Guid id, [FromBody] UpdateContactNoteDto noteDto)
|
||||||
{
|
{
|
||||||
return Ok();
|
var response = await _directoryHelper.UpdateContactNote(id, noteDto);
|
||||||
//var response = await _directoryHelper.UpdateContactNote(id, noteDto);
|
if (response.StatusCode == 200)
|
||||||
//if (response.StatusCode == 200)
|
{
|
||||||
//{
|
return Ok(response);
|
||||||
// return Ok(response);
|
}
|
||||||
//}
|
else if (response.StatusCode == 404)
|
||||||
//else if (response.StatusCode == 404)
|
{
|
||||||
//{
|
return NotFound(response);
|
||||||
// return NotFound(response);
|
}
|
||||||
//}
|
else
|
||||||
//else
|
{
|
||||||
//{
|
return BadRequest(response);
|
||||||
// return BadRequest(response);
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("note/{id}")]
|
[HttpDelete("note/{id}")]
|
||||||
public async Task<IActionResult> DeleteContactNote(Guid id)
|
public async Task<IActionResult> DeleteContactNote(Guid id)
|
||||||
{
|
{
|
||||||
return Ok();
|
var response = await _directoryHelper.DeleteContactNote(id);
|
||||||
//var response = await _directoryHelper.DeleteContactNote(id);
|
return Ok(response);
|
||||||
//return Ok(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------- Bucket --------------------------------
|
// -------------------------------- Bucket --------------------------------
|
||||||
|
@ -646,6 +646,87 @@ 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);
|
_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<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResponse<object>> 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<object>.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<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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
public async Task<ApiResponse<object>> 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<object>.SuccessResponse(new { }, "Note deleted successfully", 200);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------- Bucket --------------------------------
|
// -------------------------------- Bucket --------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user