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
15c665236b
commit
f820bedba3
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user