public async Task <List <TreeData> > GetFullProductCategoryTree(string tenantId, string languageId) { var infoProductCategorys = await _productCategoryRepository.GetAllActivatedProductCategory(tenantId, languageId); if (infoProductCategorys == null || !infoProductCategorys.Any()) { return(null); } return(RenderTree(infoProductCategorys, null)); List <TreeData> RenderTree(List <ProductCategorySearchViewModel> productCategorys, int?parentId) { var tree = new List <TreeData>(); var parents = infoProductCategorys.Where(x => x.ParentId == parentId).ToList(); if (parents.Any()) { parents.ForEach(parent => { var treeData = new TreeData { Id = parent.Id, Text = parent.Name, ParentId = parent.ParentId, IdPath = parent.IdPath, Data = parent, ChildCount = parent.ChildCount, Icon = string.Empty, State = new GHM.Infrastructure.Models.State(), Children = RenderTree(parents, parent.Id) }; tree.Add(treeData); }); } return(tree); } }