public async Task <List <GetTreeViewDTO> > GetTreeWithParentsOnly(Guid?rootId = null) { var dtosFromCategories = await _dbContext.Categories.Select(category => GetTreeViewDTO.FromCategory(category)).ToListAsync(); await _dbContext.SaveChangesAsync(); return(dtosFromCategories.CreateTree(rootId).ToList()); }
public async Task <List <GetTreeViewDTO> > GetTreeView(Guid?rootId = null) { var dtosFromCategories = await _dbContext.Categories.Select(category => GetTreeViewDTO.FromCategory(category)).ToListAsync(); var dtosFromPages = await _dbContext.Pages.Select(page => GetTreeViewDTO.FromPage(page)).ToListAsync(); await _dbContext.SaveChangesAsync(); return(dtosFromCategories.Concat(dtosFromPages).ToList().CreateTreeIncludeRoot(rootId)); }
public static List <GetTreeViewDTO> CreateTreeIncludeRoot(this List <GetTreeViewDTO> collection, Guid?rootId) { try { GetTreeViewDTO root = collection.First(c => c.Id == rootId); root.Childs = collection.CreateTree(root.Id); return(new List <GetTreeViewDTO>() { root }); } catch (System.Exception) { return(collection.CreateTree()); } }