public static EagerlyLoadQueryResult <T> IncludeTaxonomyFields <T>(this IContentQuery <T> query, bool loadTermsContainter) where T : class, IContent { var manager = query.ContentManager; query = query.Join <TermsPartRecord>().WithQueryHints(new QueryHints().ExpandRecords("TermsPartRecord.Terms")); var eagerlyLoadQueryResult = new EagerlyLoadQueryResult <T>(query.List(), manager); return(eagerlyLoadQueryResult.IncludeTaxonomyFields(loadTermsContainter)); }
public ActionResult Index(PagerParameters pagerParameters, SearchVM search, int id = 0) { if (!_orchardServices.Authorizer.Authorize(TestPermission)) { return(new HttpUnauthorizedResult()); } dynamic Options = new System.Dynamic.ExpandoObject(); if (id >= 0) { Options.Campaign = _contentManager.Get(id); } else { // Options.Campaign = ""; // devo inserire la proprietà Campaign altrimenti index va in exception Options.Campaign = new System.Dynamic.ExpandoObject(); Options.Campaign.Id = id; } var expression = search.Expression; IContentQuery <ContentItem> contentQuery = _contentManager.Query(VersionOptions.Latest).ForType(contentType).OrderByDescending <CommonPartRecord>(cpr => cpr.ModifiedUtc); /*Nel caso di flash advertising la campagna è -10, quindi il filtro è sempre valido.*/ if (id > 0) { contentQuery = contentQuery.Where <CommunicationAdvertisingPartRecord>(w => w.CampaignId.Equals(id) ); } else { contentQuery = contentQuery.Join <CommunicationAdvertisingPartRecord>().Where(w => w.CampaignId.Equals(0)); } if (!string.IsNullOrEmpty(search.Expression)) { contentQuery = contentQuery.Where <TitlePartRecord>(w => w.Title.Contains(expression)); } Pager pager = new Pager(_orchardServices.WorkContext.CurrentSite, pagerParameters); var pagerShape = _orchardServices.New.Pager(pager).TotalItemCount(contentQuery.Count()); var pageOfContentItems = contentQuery.Slice(pager.GetStartIndex(), pager.PageSize) .Select(p => new ContentIndexVM { Id = p.Id, Title = ((dynamic)p).TitlePart.Title, ModifiedUtc = ((dynamic)p).CommonPart.ModifiedUtc, UserName = ((dynamic)p).CommonPart.Owner != null ? ((dynamic)p).CommonPart.Owner.UserName : "******", ContentItem = p }).ToList(); var model = new SearchIndexVM(pageOfContentItems, search, pagerShape, Options); return(View((object)model)); }
private IContentQuery <ContentItem> OrderByPosition(IContentQuery <ContentItem> query) { return(query.Join <ContainablePartRecord>().OrderByDescending(x => x.Position)); }
private IContentQuery<ContentItem> OrderByPosition(IContentQuery<ContentItem> query) { return query.Join<ContainablePartRecord>().OrderByDescending(x => x.Position); }
protected override DriverResult Display(RelatedContentWidgetPart part, string displayType, dynamic shapeHelper) { List <string> tags = part.TagList .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Where(s => !String.IsNullOrEmpty(s)) .Distinct() .ToList(); // If we have no tags..... if (tags.Count < 1) { return(ContentShape("Parts_RelatedContentWidget", () => shapeHelper.Parts_RelatedContentWidget( ContentItems: shapeHelper.List() ))); } // See if we can find the current page/content id to filter it out // from the related content if necessary. int currentItemId = -1; if (part.ExcludeCurrentItemIfMatching) { currentItemId = TryGetCurrentContentId(-1); } // Setup a query on the tags part IContentQuery <TagsPart, TagsPartRecord> query = _cms.Query <TagsPart, TagsPartRecord>(); if (part.MustHaveAllTags) { // Add where conditions for every tag specified foreach (string tag in tags) { string tag1 = tag; // Prevent access to modified closure query.Where(tpr => tpr.Tags.Any(t => t.TagRecord.TagName == tag1)); } } else { // Add where condition for any tag specified query.Where(tpr => tpr.Tags.Any(t => tags.Contains(t.TagRecord.TagName))); } // Finish the query (exclude current, do ordering and slice max items) and execute IEnumerable <TagsPart> parts = query.Join <CommonPartRecord>() .Where(cpr => cpr.Id != currentItemId) .OrderByDescending(cpr => cpr.PublishedUtc) .Slice(part.MaxItems); // Create a list and push our display content items in var list = shapeHelper.List(); list.AddRange(parts.Select(p => _cms.BuildDisplay(p, "Summary"))); return(ContentShape("Parts_RelatedContentWidget", () => shapeHelper.Parts_RelatedContentWidget( ShowListOnly: part.ShowListOnly, ContentItems: list ))); }