Пример #1
0
        public object RoutePartial(LocationItemPage.LocationItemPage content, SegmentContext segmentContext)
        {
            var elements = segmentContext.RemainingPath.Split('/');

            segmentContext.RemainingPath = string.Empty;

            TagPage.TagPage cp         = null;
            var             catpages   = SearchClient.Instance.Search <TagPage.TagPage>().Take(100).GetContentResult().ToList();
            var             continents = SearchClient.Instance.Search <LocationItemPage.LocationItemPage>()
                                         .TermsFacetFor(f => f.Continent)
                                         .Take(0)
                                         .GetContentResult()
                                         .TermsFacetFor(f => f.Continent)
                                         .Terms.Select(tc => tc.Term.ToLower())
                                         .ToList();

            var additionalcats = new List <string>();

            foreach (var s in elements)
            {
                var k = s.ToLower();
                if (continents.Contains(k))
                {
                    segmentContext.SetCustomRouteData("Continent", s);
                }
                else if (cp == null)
                {
                    cp = catpages.FirstOrDefault(c => c.URLSegment.ToLower() == k);
                }
                else
                {
                    var cat = catpages.FirstOrDefault(c => c.URLSegment.ToLower() == k);
                    if (cat == null)
                    {
                        return(null);
                    }

                    additionalcats.Add(cat.Name);
                }

                //if s is category and category page is null, set category page.
                //if s is continent, set continent
                //if s is another category, set other category
            }
            if (additionalcats.Count > 0)
            {
                segmentContext.SetCustomRouteData("Category", string.Join(",", additionalcats.ToArray()));
            }

            return(cp);
        }
Пример #2
0
        // this method must convert a partial URL path into a Category entity
        // e.g. the URL "/Northwind/Meat_Poultry"
        // into the category named "Meat/Poultry"
        public object RoutePartial(NorthwindPage content,
                                   SegmentContext segmentContext)
        {
            // get the next part from the URL, i.e. what comes after "/Northwind/"
            var categorySegment = segmentContext.GetNextValue(
                segmentContext.RemainingPath);
            var categoryName = categorySegment.Next;

            // find the matching Category entity
            var db = new Northwind();

            db.Configuration.ProxyCreationEnabled = false;
            db.Configuration.LazyLoadingEnabled   = false;

            var alternativeCategory = categoryName.Replace('_', '/');
            var category            = db.Categories
                                      .Include(c => c.Products)
                                      .SingleOrDefault(c =>
                                                       (c.CategoryName == categoryName) ||
                                                       (c.CategoryName == alternativeCategory));

            if (category != null)
            {
                // store the found Category in the route data
                // so it can be passed into a view
                segmentContext.SetCustomRouteData("category", category);

                // store the remaining path so it could be processed
                // by another partial router, perhaps for Products
                segmentContext.RemainingPath = categorySegment.Remaining;
            }

            return(category);
        }
Пример #3
0
        /// <summary>
        ///     Takes care of partial routing of <see cref="TaxonomyData"/> below a routed content instance.
        /// </summary>
        /// <param name="content">The content that the page route has been able to route to.</param>
        /// <param name="segmentContext">The segment context containing the remaining part of url.</param>
        /// <returns>
        ///     A <see cref="ContentReference"/> to <paramref name="content"/> and if any routed
        ///     object is found, it's added to the custom routed data object.
        /// </returns>
        public object RoutePartial(PageData content, SegmentContext segmentContext)
        {
            // We should only use this router if the current page type is matching our instance.
            if (content is TRootPageType == false)
            {
                return(null);
            }

            var taxonomyData = this.GetTaxonomyDataRecursively(segmentContext);

            if (taxonomyData != null)
            {
                segmentContext.SetCustomRouteData(TaxonomyDataValueProvider.Prefix, taxonomyData);

                // We should still route to the "root" content even if we found a taxonomy item.
                // We're storing the taxonomy in route data so we have a reference to it and make use
                // of it in a value provider.
                segmentContext.RoutedContentLink = content.ContentLink;

                return(content);
            }

            segmentContext.RoutedContentLink = null;

            return(null);
        }
        public object RoutePartial(ICategoryRoutableContent content, SegmentContext segmentContext)
        {
            var thisSegment = segmentContext.RemainingPath;
            var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);

            while (string.IsNullOrEmpty(nextSegment.Remaining) == false)
            {
                nextSegment = segmentContext.GetNextValue(nextSegment.Remaining);
            }

            if (string.IsNullOrWhiteSpace(nextSegment.Next) == false)
            {
                var         localizableContent = content as ILocale;
                CultureInfo preferredCulture   = localizableContent?.Language ?? ContentLanguage.PreferredCulture;

                string[] categoryUrlSegments = nextSegment.Next.Split(new [] { CategorySeparator }, StringSplitOptions.RemoveEmptyEntries);
                var      categories          = new List <CategoryData>();

                foreach (var categoryUrlSegment in categoryUrlSegments)
                {
                    var category = CategoryLoader.GetFirstBySegment <CategoryData>(categoryUrlSegment, preferredCulture);

                    if (category == null)
                    {
                        return(null);
                    }

                    categories.Add(category);
                }

                segmentContext.RemainingPath = thisSegment.Substring(0, thisSegment.LastIndexOf(nextSegment.Next, StringComparison.InvariantCultureIgnoreCase));
                segmentContext.SetCustomRouteData(CategoryRoutingConstants.CurrentCategory, categories[0]);
                segmentContext.SetCustomRouteData(CategoryRoutingConstants.CurrentCategories, categories);
                segmentContext.RoutedContentLink = content.ContentLink;
                segmentContext.RoutedObject      = content;

                return(content);
            }

            return(null);
        }
        public object RoutePartial(IContent content, SegmentContext segmentContext)
        {
            var context = _httpContextAccessor();
            var request = context?.Request;

            if (request != null && request.AcceptTypes.Contains(RoutingConstants.JsonContentType))
            {
                var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);
                if (PropertyExist(content, nextSegment.Next))
                {
                    segmentContext.SetCustomRouteData(RoutingConstants.RoutedPropertyKey, nextSegment.Next);
                    segmentContext.RemainingPath = nextSegment.Remaining;
                    return(content);
                }
            }
            return(null);
        }