public List<ComboTree> GetComboTreeCategory(int id) { IProductCategoryService productCategoryService = new ProductCategoryService(); var data = productCategoryService.GetProductCategory(); List<ComboTree> result=new List<ComboTree>(); var root = data.Where(s => s.Depth == id); foreach (var categoryInfo in root) { var comboTree = new ComboTree(); comboTree.Id = categoryInfo.Id; comboTree.Text = categoryInfo.Name; comboTree.Children = GetComboTreeChildren(comboTree, categoryInfo, data); result.Add(comboTree); } return result; }
public List<ComboTree> GetComboTreeChildren2(ComboTree comboTree, ArticleCategoryInfo category, List<ArticleCategoryInfo> data) { var childrens = data.Where(s => s.Depth == category.Depth + 1 && s.Lft > category.Lft && s.Rgt < category.Rgt); var childs = new List<ComboTree>(); foreach (var productCategoryInfo in childrens) { var child = new ComboTree(); child.Id = productCategoryInfo.Id; child.Text = productCategoryInfo.Name; childs.Add(child); } comboTree.Children = childs; foreach (var child in comboTree.Children) { var temp = data.FirstOrDefault(s => s.Id == child.Id); if (temp != null) { this.GetComboTreeChildren2(child, temp, data); } } return comboTree.Children; }
public List<ComboTree> GetComboTreeArticleCategory(int id) { IArticleCategoryService articleCategoryService = new ArticleCategoryService(); var data = articleCategoryService.GetAllArticleCategory(); List<ComboTree> result = new List<ComboTree>(); var root = data.Where(s => s.Depth == id); foreach (var articleCategoryInfo in root) { var comboTree = new ComboTree(); comboTree.Id = articleCategoryInfo.Id; comboTree.Text = articleCategoryInfo.Name; comboTree.Children = GetComboTreeChildren2(comboTree, articleCategoryInfo, data); result.Add(comboTree); } return result; }