Exemplo n.º 1
0
        private async Task <CustomEntityDetails> MapAsync(
            GetCustomEntityDetailsByIdQuery query,
            CustomEntityVersion dbVersion,
            IExecutionContext executionContext
            )
        {
            if (dbVersion == null)
            {
                return(null);
            }

            var entity = MapInitialData(dbVersion, executionContext);

            // Re-map IsPublished checking to see if there is a published version in the history
            if (entity.IsPublished && entity.LatestVersion.WorkFlowStatus != WorkFlowStatus.Published)
            {
                entity.IsPublished = await _dbContext
                                     .CustomEntityVersions
                                     .AnyAsync(v => v.CustomEntityId == query.CustomEntityId && v.WorkFlowStatusId == (int)WorkFlowStatus.Published);
            }

            if (dbVersion.CustomEntity.LocaleId.HasValue)
            {
                var getLocaleQuery = new GetActiveLocaleByIdQuery(dbVersion.CustomEntity.LocaleId.Value);
                entity.Locale = await _queryExecutor.ExecuteAsync(getLocaleQuery, executionContext);
            }

            // Custom Mapping
            await MapDataModelAsync(query, dbVersion, entity.LatestVersion, executionContext);

            await MapPages(dbVersion, entity, executionContext);

            return(entity);
        }
Exemplo n.º 2
0
        public async Task<CustomEntityRenderDetails> ExecuteAsync(GetCustomEntityRenderDetailsByIdQuery query, IExecutionContext executionContext)
        {
            var dbResult = await QueryCustomEntityAsync(query, executionContext);
            if (dbResult == null) return null;

            var entity = await MapCustomEntityAsync(dbResult);

            if (dbResult.CustomEntity.LocaleId.HasValue)
            {
                var getLocaleQuery = new GetActiveLocaleByIdQuery(dbResult.CustomEntity.LocaleId.Value);
                entity.Locale = await _queryExecutor.ExecuteAsync(getLocaleQuery, executionContext);
            }

            entity.Regions = await QueryRegions(query).ToListAsync();
            var dbPageBlocks = await QueryPageBlocks(entity).ToListAsync();

            var allBlockTypes = await _queryExecutor.ExecuteAsync(new GetAllPageBlockTypeSummariesQuery(), executionContext);
            await _entityVersionPageBlockMapper.MapRegionsAsync(dbPageBlocks, entity.Regions, allBlockTypes, query.PublishStatus);

            var routingQuery = new GetPageRoutingInfoByCustomEntityIdQuery(dbResult.CustomEntityId);
            var routing = await _queryExecutor.ExecuteAsync(routingQuery, executionContext);
            entity.PageUrls = MapPageRoutings(routing, dbResult);

            return entity;
        }
Exemplo n.º 3
0
        public async Task <CustomEntityRenderDetails> ExecuteAsync(GetCustomEntityRenderDetailsByIdQuery query, IExecutionContext executionContext)
        {
            var dbResult = await QueryCustomEntityAsync(query, executionContext);

            if (dbResult == null)
            {
                return(null);
            }

            var entity = MapCustomEntity(dbResult, executionContext);

            if (dbResult.CustomEntity.LocaleId.HasValue)
            {
                var getLocaleQuery = new GetActiveLocaleByIdQuery(dbResult.CustomEntity.LocaleId.Value);
                entity.Locale = await _queryExecutor.ExecuteAsync(getLocaleQuery, executionContext);
            }

            var pageRoutesQuery = new GetPageRoutingInfoByCustomEntityIdQuery(dbResult.CustomEntityId);
            var pageRoutes      = await _queryExecutor.ExecuteAsync(pageRoutesQuery, executionContext);

            entity.PageUrls = MapPageRoutings(pageRoutes, dbResult);

            var selectedRoute = pageRoutes.FirstOrDefault(r => r.PageRoute.PageId == query.PageId);

            if (selectedRoute != null)
            {
                var pageVersion = selectedRoute.PageRoute.Versions.GetVersionRouting(PublishStatusQuery.PreferPublished);
                if (pageVersion == null)
                {
                    throw new Exception($"Error mapping routes: {nameof(pageVersion)} cannot be null. A page route should always have at least one version.");
                }

                entity.Regions = await GetRegionsAsync(pageVersion.PageTemplateId);

                var dbPageBlocks = await GetPageBlocksAsync(entity.CustomEntityVersionId, selectedRoute.PageRoute.PageId);

                var allBlockTypes = await _queryExecutor.ExecuteAsync(new GetAllPageBlockTypeSummariesQuery(), executionContext);

                await _entityVersionPageBlockMapper.MapRegionsAsync(dbPageBlocks, entity.Regions, allBlockTypes, query.PublishStatus);
            }
            else
            {
                entity.Regions = Array.Empty <CustomEntityPageRegionRenderDetails>();
            }

            return(entity);
        }
        /// <summary>
        /// Maps an EF CustomEntityVersion record from the db into a CustomEntityRenderSummary
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbResult">CustomEntityVersion record from the database.</param>
        /// <param name="executionContext">Context to run any sub queries under.</param>
        public async Task <CustomEntityRenderSummary> MapAsync(
            CustomEntityVersion dbResult,
            IExecutionContext executionContext
            )
        {
            if (dbResult == null)
            {
                return(null);
            }

            var routingQuery = GetPageRoutingQuery(dbResult);
            var routing      = await _queryExecutor.ExecuteAsync(routingQuery, executionContext);

            ActiveLocale locale = null;

            if (dbResult.CustomEntity.LocaleId.HasValue)
            {
                var getLocaleQuery = new GetActiveLocaleByIdQuery(dbResult.CustomEntity.LocaleId.Value);
                locale = await _queryExecutor.ExecuteAsync(getLocaleQuery, executionContext);
            }

            return(MapSingle(dbResult, routing, locale));
        }