Added an API to get contact category by its size
This commit is contained in:
parent
9a5be28196
commit
a4aae7ebbe
@ -112,55 +112,6 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
return ApiResponse<object>.SuccessResponse(new { }, "Category deleted successfully", 200);
|
return ApiResponse<object>.SuccessResponse(new { }, "Category deleted successfully", 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ApiResponse<object>> GetContactCategoriesList()
|
|
||||||
{
|
|
||||||
Guid tenantId = _userHelper.GetTenantId();
|
|
||||||
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
|
||||||
|
|
||||||
var categoryList = await _context.ContactCategoryMasters.Where(c => c.TenantId == tenantId).ToListAsync();
|
|
||||||
List<ContactCategoryVM> contactCategories = new List<ContactCategoryVM>();
|
|
||||||
foreach (var category in categoryList)
|
|
||||||
{
|
|
||||||
ContactCategoryVM categoryVM = category.ToContactCategoryVMFromContactCategoryMaster();
|
|
||||||
contactCategories.Add(categoryVM);
|
|
||||||
}
|
|
||||||
_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);
|
|
||||||
}
|
|
||||||
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