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, executionContext); } 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)); }
private async Task <CustomEntityDetails> MapAsync( GetCustomEntityDetailsByIdQuery query, CustomEntityVersion dbVersion, IExecutionContext executionContext ) { if (dbVersion == null) { return(null); } var entity = MapInitialData(dbVersion, executionContext); if (entity.LatestVersion.WorkFlowStatus == WorkFlowStatus.Published) { entity.HasPublishedVersion = true; } else { entity.HasPublishedVersion = 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); }