public async Task <PagerInfo> InitializePager(int pageSize, string baseUrl, string listItemsContentType, bool showPages = true)
        {
            _pagerInfo = new PagerInfo
            {
                PageSize         = pageSize,
                PageBaseUrl      = baseUrl,
                ItemsContentType = listItemsContentType,
                ShowPages        = showPages
            };

            var itemsCount = await _orchard.QueryContentItemsAsync(q => q.Where(c => c.ContentType == listItemsContentType && c.Published));

            _pagerInfo.TotalPages = (int)Math.Ceiling(itemsCount.Count() / (double)_pagerInfo.PageSize);

            return(_pagerInfo);
        }
        public async Task OnGetAsync(string projectTitle)
        {
            Project = _orchardHelper.QueryContentItemsAsync(q => q.Where(c => c.DisplayText == projectTitle))
                      .GetAwaiter().GetResult().SingleOrDefault();

            var relatedProjects = (IEnumerable <string>)Project?.Content.Project.RelatedProjects?.ContentItemIds?.ToObject <string[]>();

            if (relatedProjects?.Count() > 0)
            {
                RelatedProjects = await
                                  _orchardHelper.GetContentItemsByIdAsync(relatedProjects);
            }
        }
        public async Task OnGetAsync(int?pageIndex, string BlogPostTitle)
        {
            if (!string.IsNullOrEmpty(BlogPostTitle))
            {
                BlogPost = (await _orchard.QueryContentItemsAsync(q => q.Where(c => c.DisplayText == BlogPostTitle && c.Published))).SingleOrDefault();
            }
            else
            {
                Blog = await _dataRetriever.InitializeContainer("Blog");

                PagerInfo = await _dataRetriever.InitializePager(4, "/blog2", "BlogPost", false);

                PagerInfo.CurrentPage        = pageIndex ?? 1;
                PagerInfo.CurrentItemsOnPage = await _dataRetriever.GetCurrentPage();
            }
        }
Пример #4
0
 /// <summary>
 /// Loads content items of a specific type.
 /// </summary>
 /// <param name="contentType">The content type to load.</param>
 public static Task <IEnumerable <ContentItem> > GetRecentContentItemsByContentTypeAsync(this IOrchardHelper orchardHelper, string contentType, int maxContentItems = 10)
 {
     return(orchardHelper.QueryContentItemsAsync(query => query.Where(x => x.ContentType == contentType && x.Published == true).OrderByDescending(x => x.CreatedUtc).Take(maxContentItems)));
 }