private void constructTree(Node node, ICollection<CategoryView> categories, int? currentId) { var children = categories.Where(c => c.parentId == currentId); foreach (var child in children) { Node leaf = new Node(); leaf.data = child; node.children.Add(leaf); constructTree(leaf, categories, child.id); } }
public Node GetTree() { var categories = repo.getAllCategories(); var categoryViews = CategoryView.getViews(categories); Node tree = new Node(); constructTree(tree, categoryViews.ToArray(), null); return tree; }