コード例 #1
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));
        }
コード例 #2
0
        public async Task <IHttpActionResult> Get([FromUri] SearchPageSummariesQuery query)
        {
            if (query == null)
            {
                query = new SearchPageSummariesQuery();
            }

            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(this, results));
        }
コード例 #3
0
        public async Task <IActionResult> Get(
            [FromQuery] SearchPageSummariesQuery query,
            [FromQuery] GetPageSummariesByIdRangeQuery rangeQuery
            )
        {
            if (rangeQuery != null && rangeQuery.PageIds != null)
            {
                var rangeResults = await _queryExecutor.ExecuteAsync(rangeQuery);

                return(_apiResponseHelper.SimpleQueryResponse(this, rangeResults.FilterAndOrderByKeys(rangeQuery.PageIds)));
            }

            if (query == null)
            {
                query = new SearchPageSummariesQuery();
            }

            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(this, results));
        }
コード例 #4
0
        public async Task <JsonResult> Get(
            [FromQuery] SearchPageSummariesQuery query,
            [FromQuery] GetPageSummariesByIdRangeQuery rangeQuery
            )
        {
            if (rangeQuery != null && rangeQuery.PageIds != null)
            {
                return(await _apiResponseHelper.RunWithResultAsync(async() =>
                {
                    return await _domainRepository
                    .WithQuery(rangeQuery)
                    .FilterAndOrderByKeys(rangeQuery.PageIds)
                    .ExecuteAsync();
                }));
            }

            if (query == null)
            {
                query = new SearchPageSummariesQuery();
            }
            ApiPagingHelper.SetDefaultBounds(query);

            return(await _apiResponseHelper.RunQueryAsync(query));
        }
コード例 #5
0
 public IEnumerable <IPermissionApplication> GetPermissions(SearchPageSummariesQuery query)
 {
     yield return(new PageReadPermission());
 }
コード例 #6
0
        private IQueryable <Page> CreateQuery(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var dbQuery = _dbContext
                          .PagePublishStatusQueries
                          .AsNoTracking()
                          .Include(p => p.Page)
                          .ThenInclude(p => p.Creator)
                          .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);
                var textQuery    = sluggedQuery.Replace("-", " ");

                dbQuery = dbQuery.Where(p =>
                                        (p.Page.UrlPath.Contains(sluggedQuery) || (p.Page.UrlPath == string.Empty && p.Page.PageDirectory.UrlPath.Contains(sluggedQuery))) ||
                                        p.PageVersion.Title.Contains(textQuery));
            }

            // 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));
        }
コード例 #7
0
 public IDomainRepositoryQueryContext <PagedQueryResult <PageSummary> > AsSummaries(SearchPageSummariesQuery query)
 {
     return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }