private async Task <PagedQueryResult <CustomEntityVersion> > GetQueryAsync(SearchCustomEntityRenderSummariesQuery query, IExecutionContext executionContext)
        {
            var definition = _customEntityDefinitionRepository.GetByCode(query.CustomEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            var dbQuery = _dbContext
                          .CustomEntityPublishStatusQueries
                          .AsNoTracking()
                          .Include(c => c.CustomEntityVersion)
                          .ThenInclude(c => c.CustomEntity)
                          .FilterByCustomEntityDefinitionCode(query.CustomEntityDefinitionCode)
                          .FilterActive()
                          .FilterByStatus(query.PublishStatus, executionContext.ExecutionDate);

            // Filter by locale
            if (query.LocaleId > 0 && definition.HasLocale)
            {
                dbQuery = dbQuery.Where(p => p.CustomEntity.LocaleId == query.LocaleId);
            }
            else
            {
                dbQuery = dbQuery.Where(p => !p.CustomEntity.LocaleId.HasValue);
            }

            var dbPagedResult = await dbQuery
                                .SortBy(definition, query.SortBy, query.SortDirection)
                                .Select(p => p.CustomEntityVersion)
                                .ToPagedResultAsync(query);

            return(dbPagedResult);
        }
        public IEnumerable <IPermissionApplication> GetPermissions(SearchCustomEntityRenderSummariesQuery query)
        {
            var definition = _customEntityDefinitionRepository.GetByCode(query.CustomEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            yield return(new CustomEntityReadPermission(definition));
        }
        public PagedQueryResult <CustomEntityRenderSummary> Execute(SearchCustomEntityRenderSummariesQuery query, IExecutionContext executionContext)
        {
            var dbQuery       = GetQuery(query);
            var dbPagedResult = dbQuery.ToPagedResult(query);
            var results       = _customEntityRenderSummaryMapper.MapSummaries(dbPagedResult.Items, executionContext);

            return(dbPagedResult.ChangeType(results));
        }
        private IQueryable <CustomEntityVersion> GetQuery(SearchCustomEntityRenderSummariesQuery query)
        {
            var definition = _queryExecutor.GetById <CustomEntityDefinitionSummary>(query.CustomEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            var dbQuery = _dbContext
                          .CustomEntityVersions
                          .AsNoTracking()
                          .Where(e => e.CustomEntity.CustomEntityDefinitionCode == query.CustomEntityDefinitionCode)
                          .Where(v => v.WorkFlowStatusId == (int)Domain.WorkFlowStatus.Draft || v.WorkFlowStatusId == (int)Domain.WorkFlowStatus.Published)
                          .GroupBy(e => e.CustomEntityId, (key, g) => g.OrderByDescending(v => v.WorkFlowStatusId == (int)Domain.WorkFlowStatus.Draft).FirstOrDefault())
                          .Include(e => e.CustomEntity);

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

            switch (query.SortBy)
            {
            case CustomEntityQuerySortType.Default:
            case CustomEntityQuerySortType.Natural:
                if (definition.Ordering != CustomEntityOrdering.None)
                {
                    dbQuery = dbQuery
                              .OrderByWithSortDirection(e => !e.CustomEntity.Ordering.HasValue, query.SortDirection)
                              .ThenByWithSortDirection(e => e.CustomEntity.Ordering, query.SortDirection)
                              .ThenByDescendingWithSortDirection(e => e.CreateDate, query.SortDirection);
                }
                else
                {
                    dbQuery = dbQuery
                              .OrderByDescendingWithSortDirection(e => e.CreateDate, query.SortDirection);
                }
                break;

            case CustomEntityQuerySortType.Title:
                dbQuery = dbQuery
                          .OrderByWithSortDirection(e => e.Title, query.SortDirection);
                break;

            case CustomEntityQuerySortType.CreateDate:
                dbQuery = dbQuery
                          .OrderByDescendingWithSortDirection(e => e.CreateDate, query.SortDirection);
                break;
            }

            return(dbQuery);
        }
Beispiel #5
0
        private async Task <PagedQueryResult <CustomEntityVersion> > GetQueryAsync(SearchCustomEntityRenderSummariesQuery query, IExecutionContext executionContext)
        {
            var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(query.CustomEntityDefinitionCode);
            var definition      = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            var dbQuery = _dbContext
                          .CustomEntityPublishStatusQueries
                          .AsNoTracking()
                          .Include(e => e.CustomEntityVersion)
                          .ThenInclude(e => e.CustomEntity)
                          .FilterByCustomEntityDefinitionCode(query.CustomEntityDefinitionCode)
                          .FilterByActive()
                          .FilterByStatus(query.PublishStatus, executionContext.ExecutionDate);

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

            switch (query.SortBy)
            {
            case CustomEntityQuerySortType.Default:
            case CustomEntityQuerySortType.Natural:
                if (definition.Ordering != CustomEntityOrdering.None)
                {
                    dbQuery = dbQuery
                              .OrderByWithSortDirection(e => !e.CustomEntity.Ordering.HasValue, query.SortDirection)
                              .ThenByWithSortDirection(e => e.CustomEntity.Ordering, query.SortDirection)
                              .ThenByDescendingWithSortDirection(e => e.CustomEntity.CreateDate, query.SortDirection);
                }
                else
                {
                    dbQuery = dbQuery
                              .OrderByDescendingWithSortDirection(e => e.CustomEntity.CreateDate, query.SortDirection);
                }
                break;

            case CustomEntityQuerySortType.Title:
                dbQuery = dbQuery
                          .OrderByWithSortDirection(e => e.CustomEntityVersion.Title, query.SortDirection);
                break;

            case CustomEntityQuerySortType.CreateDate:
                dbQuery = dbQuery
                          .OrderByDescendingWithSortDirection(e => e.CustomEntity.CreateDate, query.SortDirection);
                break;

            case CustomEntityQuerySortType.PublishDate:
                dbQuery = dbQuery
                          .OrderByDescendingWithSortDirection(e => e.CustomEntity.PublishDate.HasValue, query.SortDirection)
                          .ThenByDescendingWithSortDirection(e => e.CustomEntity.PublishDate, query.SortDirection)
                          .ThenByDescendingWithSortDirection(e => e.CustomEntity.CreateDate, query.SortDirection)
                ;
                break;
            }

            var dbPagedResult = await dbQuery.ToPagedResultAsync(query);

            // EF doesnt support includes after select so need to run this post execution
            var results = dbPagedResult
                          .Items
                          .Select(p => p.CustomEntityVersion);

            return(dbPagedResult.ChangeType(results));
        }
Beispiel #6
0
        public async Task <PagedQueryResult <CustomEntityRenderSummary> > ExecuteAsync(SearchCustomEntityRenderSummariesQuery query, IExecutionContext executionContext)
        {
            var dbPagedResult = await GetQueryAsync(query, executionContext);

            var results = await _customEntityRenderSummaryMapper.MapAsync(dbPagedResult.Items, executionContext);

            return(dbPagedResult.ChangeType(results));
        }
Beispiel #7
0
 public Task <PagedQueryResult <CustomEntityRenderSummary> > SearchCustomEntityRenderSummariesAsync(SearchCustomEntityRenderSummariesQuery query, IExecutionContext executionContext = null)
 {
     return(_queryExecutor.ExecuteAsync(query, executionContext));
 }
 public Task <PagedQueryResult <CustomEntityRenderSummary> > AsRenderSummariesAsync(SearchCustomEntityRenderSummariesQuery query)
 {
     return(ExtendableContentRepository.ExecuteQueryAsync(query));
 }
 public IContentRepositoryQueryContext <PagedQueryResult <CustomEntityRenderSummary> > AsRenderSummaries(SearchCustomEntityRenderSummariesQuery query)
 {
     return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }