| @@ -182,18 +182,46 @@ namespace Diligent.WebAPI.Business.Services | |||
| private async Task<List<Category>> getCategoriesUserCanSee(int userId) | |||
| { | |||
| var k = await _context.UserCategories.Include(c => c.Category).ToListAsync(); | |||
| var k = await _context.UserCategories.Include(c => c.Category).ThenInclude(p => p.ParentCategory).Where(t => t.UserId == userId).ToListAsync(); | |||
| List<Category> t = new(); | |||
| foreach (var m in k) | |||
| { | |||
| if(m.UserId == userId) | |||
| Category category = m.Category; | |||
| while (true) | |||
| { | |||
| t.Add(m.Category); | |||
| bool s = false; | |||
| for (int i = 0; i < k.Count; i++) | |||
| { | |||
| if(category.Id == k[i].CategoryId) | |||
| { | |||
| s = true; | |||
| break; | |||
| } | |||
| } | |||
| if (s && category.ParentCategory is null) | |||
| { | |||
| t.Add(m.Category); | |||
| break; | |||
| } | |||
| else if(!s && category.ParentCategory is null) | |||
| { | |||
| break; | |||
| } | |||
| else if(s == true) | |||
| { | |||
| category = category.ParentCategory; | |||
| continue; | |||
| } | |||
| else | |||
| { | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| return t; | |||
| } | |||
| private List<TreeViewCategoryResponse> GetTreeCategoryItem(List<Category> items, int id) | |||
| { | |||
| List<TreeViewCategoryResponse> response = new(); | |||