private IEnumerable <SubNavigationLinkModel> GetRegularChildLinks(Page rootPage)
        {
            var res = new List <SubNavigationLinkModel>();

            foreach (var child in _pageService
                     .GetChildPages(rootPage.SystemId)
                     .Where(x => x.Status == ContentStatus.Published &&
                            x.IsActive(_channel.SystemId) &&
                            _authorizationService.HasOperation <Page>(Operations.Entity.Read, x.SystemId)))
            {
                var link = new SubNavigationLinkModel
                {
                    Name       = child.Localizations.CurrentCulture.Name,
                    Url        = _urlService.GetUrl(child),
                    IsSelected = _currentSelectedPageId == child.SystemId
                };

                if (_selectedStructureId.Contains(child.SystemId))
                {
                    link.Links = GetChildLinks(child).ToList();
                }
                else if (_pageService.GetChildPages(child.SystemId).Any(x => x.MapTo <PageModel>() != null))
                {
                    link.Links = new List <SubNavigationLinkModel>();
                }

                res.Add(link);
            }

            return(res);
        }
        private IEnumerable <SubNavigationLinkModel> GetChildLinks(Category category)
        {
            var res = new List <SubNavigationLinkModel>();

            foreach (var child in category
                     .GetChildren()
                     .Where(x => x.IsPublished(_channel.SystemId) &&
                            _renderingValidators.Validate(x)))
            {
                var link = new SubNavigationLinkModel
                {
                    Name = child.Localizations.CurrentCulture.Name,
                    Url  = child.GetUrl(_channel.SystemId)
                };

                if (_selectedStructureId.Contains(child.SystemId))
                {
                    link.IsSelected = true;
                    link.Links      = GetChildLinks(child).ToList();
                }
                else if (child.GetChildren().Any())
                {
                    link.Links = new List <SubNavigationLinkModel>();
                }
                res.Add(link);
            }

            return(res);
        }
        private IEnumerable <SubNavigationLinkModel> GetChildLinks(Category category, bool showAll = false, int level = int.MaxValue)
        {
            var res = new List <SubNavigationLinkModel>();

            foreach (var child in category.GetChildren()
                     .Where(pg => pg.IsPublished(_channel.SystemId) &&
                            _authorizationService.HasOperation <Category>(Operations.Entity.Read, pg.SystemId) &&
                            _renderingValidators.Validate(pg)))
            {
                if (showAll || _selectedStructureId.Contains(child.SystemId))
                {
                    var link = new SubNavigationLinkModel
                    {
                        Name       = child.Localizations.CurrentCulture.Name,
                        Url        = child.GetUrl(_channel.SystemId),
                        IsSelected = _selectedStructureId.Contains(child.SystemId),
                        Links      = _selectedStructureId.Contains(child.SystemId) ?
                                     GetChildLinks(child, _currentCategorySystemId == child.SystemId, level + 1).ToList() :
                                     (category.GetChildren().Any() ? new List <SubNavigationLinkModel>() : null)
                    };

                    res.Add(link);
                }
            }

            return(res);
        }
Exemple #4
0
        /// <summary>
        /// Buid Sub Navigation Model
        /// </summary>
        /// <param name="currentPageModel"></param>
        /// <returns></returns>
        public async Task <SubNavigationLinkModel> BuildAsync()
        {
            _website = _requestModelAccessor.RequestModel.WebsiteModel;
            _channel = _requestModelAccessor.RequestModel.ChannelModel;
            _page    = _requestModelAccessor.RequestModel.CurrentPageModel;

            var contentLink      = new SubNavigationLinkModel();
            var filterNavigation = _website.GetNavigationType();
            var pageTypeName     = _page.GetPageType();

            // sub navigation
            if (_routeRequestInfoAccessor.RouteRequestInfo?.Data is ProductPageData productCatalogData)
            {
                contentLink = filterNavigation == NavigationType.Category
                    ? CreateProductCategoryNavigation(productCatalogData)
                    : CreateProductFilterNavigation(productCatalogData);
            }
            else if (pageTypeName != PageTemplateNameConstants.Brand && pageTypeName != PageTemplateNameConstants.ProductList &&
                     pageTypeName != PageTemplateNameConstants.SearchResult)
            {
                contentLink = await CreatePageNavigationAsync();
            }

            return(contentLink);
        }
        /// <summary>
        /// Buid Sub Navigation Model
        /// </summary>
        /// <param name="currentPageModel"></param>
        /// <returns></returns>
        public SubNavigationLinkModel Build()
        {
            SubNavigationLinkModel contentLink = new SubNavigationLinkModel();
            var filterNavigation   = _website.GetNavigationType();
            var productCatalogData = _routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData;
            var pageTypeName       = _page.GetPageType();

            // sub navigation
            if (productCatalogData != null)
            {
                contentLink = filterNavigation == NavigationType.Category ? CreateProductCategoryNavigation(productCatalogData) : CreateProductFilterNavigation(productCatalogData);
            }
            else if (pageTypeName != PageTemplateNameConstants.Brand && pageTypeName != PageTemplateNameConstants.ProductList &&
                     pageTypeName != PageTemplateNameConstants.SearchResult)
            {
                contentLink = CreatePageNavigation();
            }

            return(contentLink);
        }