Ejemplo n.º 1
0
        protected override DriverResult Display(OptionItemPart part, string displayType, dynamic shapeHelper)
        {
            return(Combined(
                       ContentShape("Parts_OptionItemPart_Feed", () => {
                // generates a link to the RSS feed for this term
                _feedManager.Register(part.Name, "rss", new RouteValueDictionary {
                    { "optionItem", part.Id }
                });
                return null;
            }),
                       ContentShape("Parts_OptionItemPart", () => {
                var pagerParameters = new PagerParameters();
                var httpContext = _httpContextAccessor.Current();
                if (httpContext != null)
                {
                    pagerParameters.Page = Convert.ToInt32(httpContext.Request.QueryString["page"]);
                }

                var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
                var optionSet = _optionSetService.GetOptionSet(part.OptionSetId);
                var totalItemCount = 100;

                // asign Taxonomy and Term to the content item shape (Content) in order to provide
                // alternates when those content items are displayed when they are listed on a term
                var termContentItems = _optionSetService.GetContentItems(part, pager.GetStartIndex(), pager.PageSize)
                                       .Select(c => _contentManager.BuildDisplay(c, "Summary").Taxonomy(optionSet).Term(part));

                var list = shapeHelper.List();

                list.AddRange(termContentItems);

                var pagerShape = shapeHelper.Pager(pager)
                                 .TotalItemCount(totalItemCount)
                                 .Taxonomy(optionSet)
                                 .Term(part);

                return shapeHelper.Parts_TermPart(ContentItems: list, Taxonomy: optionSet, Pager: pagerShape);
            })));
        }
Ejemplo n.º 2
0
        public void Execute(FeedContext context)
        {
            var termParthId = context.ValueProvider.GetValue("term");

            if (termParthId == null)
            {
                return;
            }

            var limitValue = context.ValueProvider.GetValue("limit");
            var limit      = 20;

            if (limitValue != null)
            {
                limit = (int)limitValue.ConvertTo(typeof(int));
            }

            var containerId = (int)termParthId.ConvertTo(typeof(int));
            var container   = _contentManager.Get <OptionItemPart>(containerId);

            if (container == null)
            {
                return;
            }

            var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container));

            if (context.Format == "rss")
            {
                var link = new XElement("link");
                context.Response.Element.SetElementValue("title", inspector.Title);
                context.Response.Element.Add(link);
                context.Response.Element.SetElementValue("description", inspector.Description);

                context.Response.Contextualize(requestContext => {
                    var urlHelper  = new UrlHelper(requestContext);
                    var uriBuilder = new UriBuilder(urlHelper.RequestContext.HttpContext.Request.ToRootUrlString())
                    {
                        Path = urlHelper.RouteUrl(inspector.Link)
                    };
                    link.Add(uriBuilder.Uri.OriginalString);
                });
            }
            else
            {
                context.Builder.AddProperty(context, null, "title", inspector.Title);
                context.Builder.AddProperty(context, null, "description", inspector.Description);
                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
                });
            }

            var items = _optionSetService.GetContentItems(container, 0, limit);

            foreach (var item in items)
            {
                // call item.ContentItem to force a cast to ContentItem, and
                // thus use CorePartsFeedItemBuilder
                context.Builder.AddItem(context, item.ContentItem);
            }
        }