Implemented an API to suspend a Contact
This commit is contained in:
parent
8f267f9ef9
commit
616cebbf94
@ -107,6 +107,10 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
{
|
{
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
else if (response.StatusCode == 404)
|
||||||
|
{
|
||||||
|
return NotFound(response);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return BadRequest(response);
|
return BadRequest(response);
|
||||||
@ -120,6 +124,24 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteContact(Guid id)
|
||||||
|
{
|
||||||
|
var response = await _directoryHelper.DeleteContact(id);
|
||||||
|
if (response.StatusCode == 200)
|
||||||
|
{
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
else if (response.StatusCode == 404)
|
||||||
|
{
|
||||||
|
return NotFound(response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------- Contact Notes --------------------------------
|
// -------------------------------- Contact Notes --------------------------------
|
||||||
|
|
||||||
[HttpPost("note")]
|
[HttpPost("note")]
|
||||||
|
@ -752,6 +752,26 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_logger.LogInfo("Employee {EmployeeId} fetched list of organizations in a tenant {TenantId}", LoggedInEmployee.Id, tenantId);
|
_logger.LogInfo("Employee {EmployeeId} fetched list of organizations in a tenant {TenantId}", LoggedInEmployee.Id, tenantId);
|
||||||
return ApiResponse<object>.SuccessResponse(organizationList, $"{organizationList.Count} records of organization names fetched from contacts", 200);
|
return ApiResponse<object>.SuccessResponse(organizationList, $"{organizationList.Count} records of organization names fetched from contacts", 200);
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResponse<object>> DeleteContact(Guid id)
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
if (id != Guid.Empty)
|
||||||
|
{
|
||||||
|
Contact? contact = await _context.Contacts.FirstOrDefaultAsync(c => c.Id == id && c.TenantId == tenantId);
|
||||||
|
if (contact == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} tries to delete contact with ID {ContactId} is not found in database", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Contact not found", "Contact not found", 404);
|
||||||
|
}
|
||||||
|
contact.IsActive = false;
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_logger.LogInfo("Contact {ContactId} has been deleted by Employee {Employee}", id, LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.SuccessResponse(new { }, "Contact is deleted Successfully", 200);
|
||||||
|
}
|
||||||
|
_logger.LogInfo("Employee ID {EmployeeId} sent an empty contact id", LoggedInEmployee.Id);
|
||||||
|
return ApiResponse<object>.ErrorResponse("Contact ID is empty", "Contact ID is empty", 400);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------- Contact Notes --------------------------------
|
// -------------------------------- Contact Notes --------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user