private List <CategoryNavigationRenderingViewModel.Category> MapCategories(IEnumerable <Category> categoriesToMap) { var categoriesToReturn = new List <CategoryNavigationRenderingViewModel.Category>(); var allSubCategoryIds = categoriesToMap.SelectMany(cat => cat.Categories).Distinct().ToList(); var subCategoriesById = _catalogLibrary.GetCategories(allSubCategoryIds).ToDictionary(cat => cat.Guid); foreach (var category in categoriesToMap) { var categoryToAdd = new CategoryNavigationRenderingViewModel.Category { Name = category.DisplayName, Url = _urlService.GetUrl(_catalogContext.CurrentCatalog, new[] { category }), Categories = category.Categories .Where(id => subCategoriesById.ContainsKey(id)) .Select(id => subCategoriesById[id]) .Select(cat => new CategoryNavigationRenderingViewModel.Category { Name = cat.DisplayName, Url = _urlService.GetUrl(_catalogContext.CurrentCatalog, new[] { category, cat }) }) .ToList() }; categoriesToReturn.Add(categoryToAdd); } return(categoriesToReturn); }
private List <CategoryNavigationRenderingViewModel.Category> MapCategories(ICollection <UCommerce.EntitiesV2.Category> categoriesToMap) { var categoriesToReturn = new List <CategoryNavigationRenderingViewModel.Category>(); foreach (UCommerce.EntitiesV2.Category category in categoriesToMap) { var categoryToAdd = new CategoryNavigationRenderingViewModel.Category(); categoryToAdd.Name = category.DisplayName(); categoryToAdd.Url = CatalogLibrary.GetNiceUrlForCategory(category); categoryToAdd.Url = _catalogLibraryInternal.GetNiceUrlForCategory(null, category); categoriesToReturn.Add(categoryToAdd); categoryToAdd.Categories = MapCategories(_catalogLibraryInternal.GetCategories(category)); } return(categoriesToReturn); }