Compare commits
No commits in common. "1d03ff0e098de2f14640c12546643e51448e452e" and "801e0e18058b90d4832c66494f74c7b555cf1706" have entirely different histories.
1d03ff0e09
...
801e0e1805
@ -713,8 +713,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
[HttpDelete("contact-category/{id}")]
|
[HttpDelete("contact-category/{id}")]
|
||||||
public async Task<IActionResult> DeletecontactCategoryMaster(Guid id)
|
public async Task<IActionResult> DeletecontactCategoryMaster(Guid id)
|
||||||
{
|
{
|
||||||
var response = await _masterHelper.DeleteContactCategory(id);
|
return Ok();
|
||||||
return Ok(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------- Contact Tag --------------------------------
|
// -------------------------------- Contact Tag --------------------------------
|
||||||
|
@ -63,39 +63,6 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
_logger.LogInfo("{count} contact categoires are fetched by Employee with ID {LoggedInEmployeeId}", contactCategories.Count, LoggedInEmployee.Id);
|
_logger.LogInfo("{count} contact categoires are fetched by Employee with ID {LoggedInEmployeeId}", contactCategories.Count, LoggedInEmployee.Id);
|
||||||
return ApiResponse<object>.SuccessResponse(contactCategories, System.String.Format("{0} contact categories fetched successfully", contactCategories.Count), 200);
|
return ApiResponse<object>.SuccessResponse(contactCategories, System.String.Format("{0} contact categories fetched successfully", contactCategories.Count), 200);
|
||||||
}
|
}
|
||||||
public async Task<ApiResponse<object>> DeleteContactCategory(Guid id)
|
|
||||||
{
|
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
|
||||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
||||||
ContactCategoryMaster? contactCategory = await _context.ContactCategoryMasters.FirstOrDefaultAsync(c => c.Id == id && c.TenantId == tenantId);
|
|
||||||
if (contactCategory != null)
|
|
||||||
{
|
|
||||||
List<Contact>? existingContacts = await _context.Contacts.AsNoTracking().Where(c => c.ContactCategoryId == contactCategory.Id).ToListAsync();
|
|
||||||
if (existingContacts.Count > 0)
|
|
||||||
{
|
|
||||||
List<Contact>? contacts = new List<Contact>();
|
|
||||||
foreach (var contact in existingContacts)
|
|
||||||
{
|
|
||||||
contact.ContactCategoryId = null;
|
|
||||||
contacts.Add(contact);
|
|
||||||
}
|
|
||||||
_context.Contacts.UpdateRange(contacts);
|
|
||||||
}
|
|
||||||
_context.ContactCategoryMasters.Remove(contactCategory);
|
|
||||||
|
|
||||||
_context.DirectoryUpdateLogs.Add(new DirectoryUpdateLog
|
|
||||||
{
|
|
||||||
RefereanceId = id,
|
|
||||||
UpdatedById = LoggedInEmployee.Id,
|
|
||||||
UpdateAt = DateTime.UtcNow
|
|
||||||
});
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
_logger.LogInfo("Employee {EmployeeId} deleted contact category {ContactCategoryId}", LoggedInEmployee.Id, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogWarning("Employee {EmployeeId} tries to delete Category {CategoryId} but not found in database", LoggedInEmployee.Id, id);
|
|
||||||
return ApiResponse<object>.SuccessResponse(new { }, "Category deleted successfully", 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------- Contact Tag --------------------------------
|
// -------------------------------- Contact Tag --------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user