public async Task <PagedQueryResult <PageSummary> > ExecuteAsync(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var result = await CreateQuery(query).ToPagedResultAsync(query);

            // Finish mapping children
            _pageSummaryMapper.Map(result.Items);

            return(result);
        }
Beispiel #2
0
        public async Task <PagedQueryResult <PageSummary> > ExecuteAsync(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var dbPagedResult = await CreateQuery(query, executionContext)
                                .ToPagedResultAsync(query);

            // Finish mapping children
            var mappedResults = await _pageSummaryMapper.MapAsync(dbPagedResult.Items, executionContext);

            return(dbPagedResult.ChangeType(mappedResults));
        }
        public async Task <PagedQueryResult <PageSummary> > ExecuteAsync(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var dbPagedResult = await CreateQuery(query, executionContext)
                                .ToPagedResultAsync(query);

            // Have to refilter here because EF won't let us include related entieis after a .Select statement yet
            var items = dbPagedResult
                        .Items
                        .Select(p => p.Page)
                        .ToList();

            // Finish mapping children
            var mappedResults = await _pageSummaryMapper.MapAsync(items, executionContext);

            return(dbPagedResult.ChangeType(mappedResults));
        }
 public IContentRepositoryQueryContext <PagedQueryResult <PageSummary> > AsSummaries(SearchPageSummariesQuery query)
 {
     return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }
Beispiel #5
0
 public IEnumerable <IPermissionApplication> GetPermissions(SearchPageSummariesQuery query)
 {
     yield return(new PageReadPermission());
 }
Beispiel #6
0
 /// <summary>
 /// Search page data returning the PageSummary projection, which is primarily used
 /// to display lists of page information in the admin panel. The query isn't version
 /// specific and should not be used to render content out to a live page because some of
 /// the pages returned may be unpublished.
 /// </summary>
 /// <param name="query">Query parameters.</param>
 /// <param name="executionContext">Optional execution context to use when executing the query. Useful if you need to temporarily elevate your permission level.</param>
 public Task <PagedQueryResult <PageSummary> > SearchPageSummariesAsync(SearchPageSummariesQuery query, IExecutionContext executionContext = null)
 {
     return(_queryExecutor.ExecuteAsync(query, executionContext));
 }
        private IQueryable <PageSummary> CreateQuery(SearchPageSummariesQuery query)
        {
            var dbQuery = _dbContext
                          .Pages
                          .AsNoTracking()
                          .Where(p => !p.IsDeleted && p.WebDirectory.IsActive);


            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();
                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.PageTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            // Filter by workflow status (only draft and published are applicable
            if (query.WorkFlowStatus == WorkFlowStatus.Draft)
            {
                dbQuery = dbQuery.Where(p => p.PageVersions
                                        .OrderByDescending(v => v.CreateDate)
                                        .Where(v => !v.IsDeleted)
                                        .Take(1)
                                        .Any(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft));
            }
            else if (query.WorkFlowStatus == WorkFlowStatus.Published)
            {
                // A page might be published, but also have a draft as the latest version
                dbQuery = dbQuery.Where(p => p.PageVersions
                                        .Where(v => !v.IsDeleted)
                                        .Any(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Published));
            }

            // Filter by locale
            if (query.LocaleId > 0)
            {
                dbQuery = dbQuery.Where(p => p.LocaleId == query.LocaleId);
            }

            // Filter by directory
            if (query.WebDirectoryId > 0)
            {
                dbQuery = dbQuery.Where(p => p.WebDirectoryId == query.WebDirectoryId);
            }

            // Filter by layout
            if (query.PageTemplateId > 0)
            {
                dbQuery = dbQuery.Where(p => p.PageVersions
                                        .OrderByDescending(v => v.CreateDate)
                                        .Where(v => !v.IsDeleted)
                                        .Take(1)
                                        .Any(v => v.PageTemplateId == query.PageTemplateId));
            }

            // Filter by group
            if (query.PageGroupId > 0)
            {
                dbQuery = dbQuery.Where(p => p.PageGroupItems.Any(i => i.PageGroupId == query.PageGroupId));
            }
            return(dbQuery
                   .OrderByDescending(p => p.CreateDate)
                   .ProjectTo <PageSummary>());
        }
Beispiel #8
0
        private IQueryable <Page> CreateQuery(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var dbQuery = _dbContext
                          .PagePublishStatusQueries
                          .AsNoTracking()
                          .FilterByStatus(PublishStatusQuery.Latest, executionContext.ExecutionDate)
                          .FilterActive()
            ;

            // Filter by layout
            if (query.PageTemplateId > 0)
            {
                dbQuery = dbQuery.Where(v => v.PageVersion.PageTemplateId == query.PageTemplateId);
            }

            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();
                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.Page.PageTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            if (!string.IsNullOrWhiteSpace(query.Text))
            {
                var sluggedQuery = SlugFormatter.ToSlug(query.Text);
                dbQuery = dbQuery.Where(p => p.Page.UrlPath.Contains(sluggedQuery) || p.PageVersion.Title.Contains(query.Text));
            }

            // Filter by workflow status (only draft and published are applicable
            if (query.PublishStatus == PublishStatus.Published)
            {
                dbQuery = dbQuery.Where(p => p.Page.PublishStatusCode == PublishStatusCode.Published);
            }
            else if (query.PublishStatus == PublishStatus.Unpublished)
            {
                // A page might be published, but also have a draft as the latest version
                dbQuery = dbQuery.Where(p => p.Page.PublishStatusCode == PublishStatusCode.Unpublished);
            }

            // Filter by locale
            if (query.LocaleId > 0)
            {
                dbQuery = dbQuery.FilterByLocaleId(query.LocaleId.Value);
            }

            // Filter by directory
            if (query.PageDirectoryId > 0)
            {
                dbQuery = dbQuery.FilterByDirectoryId(query.PageDirectoryId.Value);
            }

            // Filter by group
            if (query.PageGroupId > 0)
            {
                dbQuery = dbQuery.Where(p => p.Page.PageGroupItems.Any(i => i.PageGroupId == query.PageGroupId));
            }

            return(dbQuery
                   .SortBy(query.SortBy, query.SortDirection)
                   .Select(p => p.Page)
                   .Include(p => p.Creator)
                   );
        }
 public Task <PagedQueryResult <PageSummary> > AsSummariesAsync(SearchPageSummariesQuery query)
 {
     return(ExtendableContentRepository.ExecuteQueryAsync(query));
 }
Beispiel #10
0
 public PagedQueryResult <PageSummary> SearchPageSummaries(SearchPageSummariesQuery query, IExecutionContext executionContext = null)
 {
     return(_queryExecutor.Execute(query, executionContext));
 }