private List <CategoryTreeNode> GetCategoryTreeNodesFromNameList(List <string> categoryNames) { var origTree = _categoryTreeService.GetCategoriesTree(); List <CategoryTreeNode> categories = origTree.SubCategories; var toReturn = new List <CategoryTreeNode>(); int i = 0; string currentName = categoryNames[i]; while (categories.Count > 0) { var matchingCategory = categories.FirstOrDefault(node => node.CategoryName == currentName); if (matchingCategory == null) { throw new DomainException($"Invalid category name: {currentName}"); } else { categories = matchingCategory.SubCategories; currentName = categoryNames[++i % categoryNames.Count]; toReturn.Add(matchingCategory); } } if (i < categoryNames.Count) { throw new DomainException("Invalid category names"); } return(toReturn); }
protected override Task <CategoryTreeNode> HandleQuery(CategoriesQuery request, CancellationToken cancellationToken) { var categoryTreeRoot = _categoryTreeService.GetCategoriesTree(); return(Task.FromResult(categoryTreeRoot)); }