|
|
|
@@ -23,5 +23,34 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
|
|
|
|
public async Task<Category> GetCategoryEntityById(int id) => |
|
|
|
await _context.Categories.Where(x => x.Id == id).FirstOrDefaultAsync(); |
|
|
|
|
|
|
|
public async Task<List<IsGrantedCategory>> GetCategories(int userId) |
|
|
|
{ |
|
|
|
var grantedCategories = await _context.UserCategories.Where(k => k.UserId == userId).ToListAsync(); |
|
|
|
var allCategories = await _context.Categories.ToListAsync(); |
|
|
|
var result = new List<IsGrantedCategory>(); |
|
|
|
for (int i = 0; i < allCategories.Count; i++) |
|
|
|
{ |
|
|
|
var newCategory = new IsGrantedCategory |
|
|
|
{ |
|
|
|
Id = allCategories[i].Id, |
|
|
|
Name = allCategories[i].Name, |
|
|
|
}; |
|
|
|
bool isGranted = false; |
|
|
|
for (int j = 0; j < grantedCategories.Count; j++) |
|
|
|
{ |
|
|
|
if(grantedCategories[j].CategoryId == allCategories[i].Id && userId == grantedCategories[j].UserId) |
|
|
|
{ |
|
|
|
isGranted = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
newCategory.IsChecked = isGranted; |
|
|
|
result.Add(newCategory); |
|
|
|
isGranted = false; |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |