public static List <ProductCategoryBase> GetParentListFromRoot(this ProductCategoryBase cate) { ProductCategoryBase parent = cate.Parent; List <ProductCategoryBase> list = null; while (parent != null) { if (list == null) { list = new List <ProductCategoryBase>(); } list.Insert(0, parent); parent = parent.Parent; } return(list); }
public static void BuildCateTree(this ProductCategoryBase cate, List <ProductCategoryBase> categoryList) { if (cate.Children == null) { cate.Children = new List <ProductCategoryBase>(); } foreach (var c in categoryList) { if (c.Parent.PrdCategoryId == cate.PrdCategoryId) { if (!cate.Children.Contains(c)) { cate.Children.Add(c); c.Parent = cate; BuildCateTree(c, categoryList); } } } }