Added an API to deleted ContactTag as well remove entries in contact-tag mapping table related to that tag
This commit is contained in:
parent
e76c203614
commit
9af085c2fd
@ -680,7 +680,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("contact-category/{id})")]
|
||||
[HttpGet("contact-category/{id}")]
|
||||
public async Task<IActionResult> GetContactCategoryMaster(Guid id)
|
||||
{
|
||||
return Ok();
|
||||
@ -726,7 +726,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet("contact-tag/{id})")]
|
||||
[HttpGet("contact-tag/{id}")]
|
||||
public async Task<IActionResult> GetContactTagMaster(Guid id)
|
||||
{
|
||||
return Ok();
|
||||
@ -768,7 +768,8 @@ namespace Marco.Pms.Services.Controllers
|
||||
[HttpDelete("contact-tag/{id}")]
|
||||
public async Task<IActionResult> DeletecontactTagMaster(Guid id)
|
||||
{
|
||||
return Ok();
|
||||
var response = await _masterHelper.DeleteContactTag(id);
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,33 @@ namespace Marco.Pms.Services.Helpers
|
||||
_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>> DeleteContactTag(Guid id)
|
||||
{
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
ContactTagMaster? contactTag = await _context.ContactTagMasters.FirstOrDefaultAsync(c => c.Id == id && c.TenantId == tenantId);
|
||||
if (contactTag != null)
|
||||
{
|
||||
List<ContactTagMapping>? tagMappings = await _context.ContactTagMappings.Where(t => t.ContactTagtId == contactTag.Id).ToListAsync();
|
||||
|
||||
_context.ContactTagMasters.Remove(contactTag);
|
||||
if (tagMappings.Any())
|
||||
{
|
||||
_context.ContactTagMappings.RemoveRange(tagMappings);
|
||||
}
|
||||
_context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog
|
||||
{
|
||||
RefereanceId = id,
|
||||
UpdatedById = LoggedInEmployee.Id,
|
||||
UpdateAt = DateTime.UtcNow
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
_logger.LogInfo("Employee {EmployeeId} deleted contact tag {ContactTagId}", LoggedInEmployee.Id, id);
|
||||
}
|
||||
|
||||
_logger.LogWarning("Employee {EmployeeId} tries to delete Tag {ContactTagId} but not found in database", LoggedInEmployee.Id, id);
|
||||
return ApiResponse<object>.SuccessResponse(new { }, "Tag deleted successfully", 200);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user