Exemplo n.º 1
0
        /// <summary>
        /// Resolves the relative URL path into <see cref="ContentResolverResults"/> containing either the codenames of content items, or a redirect URL.
        /// </summary>
        /// <param name="urlPath">The relative URL from the HTTP request</param>
        /// <returns>The <see cref="ContentResolverResults"/>. If Found is true and the RedirectUrl isn't empty, then it means a local redirect to a static content URL.</returns>
        public async Task <ContentResolverResults> ResolveRelativeUrlPathAsync(string urlPath, string navigationCodeName = null, int?maxDepth = null)
        {
            string cn = navigationCodeName ?? _navigationCodename;
            int    d  = maxDepth ?? _maxDepth;

            // Get the 'Navigation' item, ideally with "depth" set to the actual depth of the menu.
            var navigationItem = await _navigationProvider.GetNavigationAsync(cn, d);

            // Strip the trailing slash and split.
            string[] urlSlugs = NavigationProvider.GetUrlSlugs(urlPath);

            // Recursively iterate over modular content and match the URL slugs for the each recursion level.
            return(await ProcessUrlLevelAsync(urlSlugs, navigationItem, _rootLevel));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Index(int?year, int?month)
        {
            List <IQueryParameter> filters = new List <IQueryParameter>();

            filters.AddRange(new IQueryParameter[]
            {
                new EqualsFilter("system.type", TYPE_NAME),
                new DepthParameter(0),
                new OrderParameter(ELEMENT_NAME)
            });

            string yearString  = null;
            string monthString = null;

            if (year.HasValue && !month.HasValue)
            {
                yearString  = $"{year}-01";
                monthString = $"{year + 1}-01";
            }
            else if (year.HasValue && month.HasValue)
            {
                if (month < 12)
                {
                    yearString  = $"{year}-{GetMonthFormatted(month.Value)}";
                    monthString = $"{year}-{GetMonthFormatted(month.Value + 1)}";
                }
                else
                {
                    yearString  = $"{year}-12";
                    monthString = $"{year + 1}-01";
                }
            }

            if (year.HasValue)
            {
                filters.Add(new RangeFilter(ELEMENT_NAME, yearString, monthString));
            }

            var pageBody = await _deliveryClient.GetItemsAsync <Article>(filters);

            var navigation = await _menuItemGenerator.GenerateItemsAsync(await _navigationProvider.GetNavigationAsync());

            var pageViewModel = new PageViewModel
            {
                Navigation = navigation,
                Body       = pageBody.Items
            };

            return(View(DEFAULT_VIEW, pageViewModel));
        }
Exemplo n.º 3
0
        private async Task <ViewResult> RenderViewAsync(IEnumerable <string> codenames, string viewName)
        {
            var navigation = await _menuItemGenerator.GenerateItemsAsync(await _navigationProvider.GetNavigationAsync());

            // Separate request for page body content. Separate caching, separate depth of modular content.
            var pageBody = await _deliveryClient.GetItemsAsync <object>(new InFilter("system.codename", codenames.ToArray()));

            var pageViewModel = new PageViewModel
            {
                Navigation = navigation,
                Body       = pageBody.Items
            };

            return(View((string.IsNullOrEmpty(viewName) ? DEFAULT_VIEW : viewName), pageViewModel));
        }