private void GetChildrenNode(IContent currentContent, NodeContent node, CategoryFilter nodeFilter, IEnumerable <BestBetBase> ownStyleBestBets) { var nodeChildrenOfNode = _findClient.Search <NodeContent>() .Filter(x => x.ParentLink.ID.Match(node.ContentLink.ID)) .FilterForVisitor() .GetContentResult(); foreach (var nodeChildOfChild in nodeChildrenOfNode) { var nodeChildOfChildFilter = new CategoryFilter { DisplayName = nodeChildOfChild.DisplayName, Url = _urlResolver.GetUrl(nodeChildOfChild.ContentLink), IsActive = currentContent != null && currentContent.ContentLink == nodeChildOfChild.ContentLink, IsBestBet = ownStyleBestBets.Any(x => ((CommerceBestBetSelector)x.BestBetSelector).ContentLink.ID == nodeChildOfChild.ContentLink.ID) }; nodeFilter.Children.Add(nodeChildOfChildFilter); if (nodeChildOfChildFilter.IsActive) { nodeFilter.IsActive = nodeFilter.IsActive = true; } GetChildrenNode(currentContent, nodeChildOfChild, nodeChildOfChildFilter, ownStyleBestBets); } }
private CategoriesFilterViewModel GetCategoriesFilter(IContent currentContent, string query) { var bestBets = new BestBetRepository().List().Where(i => i.PhraseCriterion.Phrase.CompareTo(query) == 0); var ownStyleBestBets = bestBets.Where(i => i.BestBetSelector is CommerceBestBetSelector && i.HasOwnStyle); var catalogId = 0; var node = currentContent as NodeContent; if (node != null) { catalogId = node.CatalogId; } var catalog = _contentLoader.GetChildren <CatalogContentBase>(_referenceConverter.GetRootLink()) .FirstOrDefault(x => catalogId == 0 || x.CatalogId == catalogId); if (catalog == null) { return(new CategoriesFilterViewModel()); } var viewModel = new CategoriesFilterViewModel(); var nodes = _findClient.Search <NodeContent>() .Filter(x => x.ParentLink.ID.Match(catalog.ContentLink.ID)) .FilterForVisitor() .GetContentResult(); foreach (var nodeContent in nodes) { var nodeFilter = new CategoryFilter { DisplayName = nodeContent.DisplayName, Url = _urlResolver.GetUrl(nodeContent.ContentLink), IsActive = currentContent != null && currentContent.ContentLink == nodeContent.ContentLink, IsBestBet = ownStyleBestBets.Any(x => ((CommerceBestBetSelector)x.BestBetSelector).ContentLink.ID == nodeContent.ContentLink.ID) }; viewModel.Categories.Add(nodeFilter); GetChildrenNode(currentContent, nodeContent, nodeFilter, ownStyleBestBets); } return(viewModel); }