소스 검색

fixes bug for showing tree view of categories

BE_dev
Dzenis Hadzifejzovic 2 년 전
부모
커밋
a5f44dc146
1개의 변경된 파일32개의 추가작업 그리고 4개의 파일을 삭제
  1. 32
    4
      Diligent.WebAPI.Business/Services/CategoryService.cs

+ 32
- 4
Diligent.WebAPI.Business/Services/CategoryService.cs 파일 보기

@@ -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();

Loading…
취소
저장