Added an API to deleted ContactTag as well remove entries in contact-tag mapping table related to that tag

This commit is contained in:
ashutosh.nehete 2025-05-17 14:33:14 +05:30
parent ba38c857a2
commit b9b06ba54c
2 changed files with 30 additions and 3 deletions

View File

@ -680,7 +680,7 @@ namespace Marco.Pms.Services.Controllers
return Ok(response); return Ok(response);
} }
[HttpGet("contact-category/{id})")] [HttpGet("contact-category/{id}")]
public async Task<IActionResult> GetContactCategoryMaster(Guid id) public async Task<IActionResult> GetContactCategoryMaster(Guid id)
{ {
return Ok(); return Ok();
@ -726,7 +726,7 @@ namespace Marco.Pms.Services.Controllers
return Ok(response); return Ok(response);
} }
[HttpGet("contact-tag/{id})")] [HttpGet("contact-tag/{id}")]
public async Task<IActionResult> GetContactTagMaster(Guid id) public async Task<IActionResult> GetContactTagMaster(Guid id)
{ {
return Ok(); return Ok();
@ -768,7 +768,8 @@ namespace Marco.Pms.Services.Controllers
[HttpDelete("contact-tag/{id}")] [HttpDelete("contact-tag/{id}")]
public async Task<IActionResult> DeletecontactTagMaster(Guid id) public async Task<IActionResult> DeletecontactTagMaster(Guid id)
{ {
return Ok(); var response = await _masterHelper.DeleteContactTag(id);
return Ok(response);
} }
} }
} }

View File

@ -139,7 +139,33 @@ namespace Marco.Pms.Services.Helpers
_logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id); _logger.LogWarning("Employee with ID {LoggedInEmployeeId} sended empty payload", LoggedInEmployee.Id);
return ApiResponse<object>.ErrorResponse("User Send empty Payload", "User Send empty Payload", 400); 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);
}
} }
} }