public async Task ExecuteAsync(UpdatePageVersionBlockCommand command, IExecutionContext executionContext) { var dbBlock = await _dbContext .PageVersionBlocks .Include(m => m.PageBlockTypeTemplate) .Include(m => m.PageBlockType) .Include(m => m.PageVersion) .Where(l => l.PageVersionBlockId == command.PageVersionBlockId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(dbBlock, command.PageVersionBlockId); if (dbBlock.PageVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page blocks cannot be updated unless the page version is in draft status"); } if (command.PageBlockTypeId != dbBlock.PageBlockTypeId) { var pageBlockType = await _dbContext .PageBlockTypes .Where(m => m.PageBlockTypeId == command.PageBlockTypeId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(pageBlockType, command.PageBlockTypeId); dbBlock.PageBlockType = pageBlockType; } dbBlock.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.DataModel); dbBlock.UpdateDate = executionContext.ExecutionDate; if (command.PageBlockTypeTemplateId != dbBlock.PageBlockTypeTemplateId && command.PageBlockTypeTemplateId.HasValue) { dbBlock.PageBlockTypeTemplate = await _dbContext .PageBlockTypeTemplates .SingleOrDefaultAsync(m => m.PageBlockTypeId == dbBlock.PageBlockTypeId && m.PageBlockTypeTemplateId == command.PageBlockTypeTemplateId); EntityNotFoundException.ThrowIfNull(dbBlock.PageBlockTypeTemplate, command.PageBlockTypeTemplateId); } else if (command.PageBlockTypeTemplateId != dbBlock.PageBlockTypeTemplateId) { dbBlock.PageBlockTypeTemplate = null; } using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( PageVersionBlockEntityDefinition.DefinitionCode, dbBlock.PageVersionBlockId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand, executionContext); scope.QueueCompletionTask(() => OnTransactionComplete(dbBlock)); await scope.CompleteAsync(); } }
public async Task ExecuteAsync(UpdateCustomEntityDraftVersionCommand command, IExecutionContext executionContext) { var definition = _customEntityDefinitionRepository.GetByCode(command.CustomEntityDefinitionCode); var draft = await GetDraftVersionAsync(command); using (var scope = _transactionScopeFactory.Create(_dbContext)) { draft = await CreateDraftIfRequiredAsync(command, draft, executionContext); await ValidateTitleAsync(command, draft, definition, executionContext); UpdateDraft(command, draft); await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( CustomEntityVersionEntityDefinition.DefinitionCode, draft.CustomEntityVersionId, command.Model); await _commandExecutor.ExecuteAsync(dependencyCommand, executionContext); scope.QueueCompletionTask(() => OnUpdateDraftComplete(command, draft)); if (command.Publish) { await _commandExecutor.ExecuteAsync(new PublishCustomEntityCommand(draft.CustomEntityId, command.PublishDate), executionContext); } await scope.CompleteAsync(); } }
public async Task ExecuteAsync(AddCustomEntityCommand command, IExecutionContext executionContext) { var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(command.CustomEntityDefinitionCode); var definition = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext); EntityNotFoundException.ThrowIfNull(definition, command.CustomEntityDefinitionCode); await _commandExecutor.ExecuteAsync(new EnsureCustomEntityDefinitionExistsCommand(definition.CustomEntityDefinitionCode)); // Custom Validation ValidateCommand(command, definition); await ValidateIsUniqueAsync(command, definition); var entity = MapEntity(command, definition, executionContext); _dbContext.CustomEntities.Add(entity); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( CustomEntityVersionEntityDefinition.DefinitionCode, entity.CustomEntityVersions.First().CustomEntityVersionId, command.Model); await _commandExecutor.ExecuteAsync(dependencyCommand); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(entity.CustomEntityId); scope.Complete(); } _customEntityCache.ClearRoutes(definition.CustomEntityDefinitionCode); // Set Ouput command.OutputCustomEntityId = entity.CustomEntityId; await _messageAggregator.PublishAsync(new CustomEntityAddedMessage() { CustomEntityId = entity.CustomEntityId, CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode, HasPublishedVersionChanged = command.Publish }); }
public async Task ExecuteAsync(UpdateCustomEntityVersionPageBlockCommand command, IExecutionContext executionContext) { var dbBlock = await _dbContext .CustomEntityVersionPageBlocks .Include(m => m.PageBlockTypeTemplate) .Include(m => m.PageBlockType) .Include(m => m.CustomEntityVersion) .ThenInclude(v => v.CustomEntity) .Where(l => l.CustomEntityVersionPageBlockId == command.CustomEntityVersionPageBlockId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(dbBlock, command.CustomEntityVersionPageBlockId); await _permissionValidationService.EnforceCustomEntityPermissionAsync <CustomEntityUpdatePermission>(dbBlock.CustomEntityVersion.CustomEntity.CustomEntityDefinitionCode); if (dbBlock.CustomEntityVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page blocks cannot be updated unless the entity is in draft status"); } using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _pageBlockCommandHelper.UpdateModelAsync(command, dbBlock); await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( CustomEntityVersionPageBlockEntityDefinition.DefinitionCode, dbBlock.CustomEntityVersionPageBlockId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand); scope.Complete(); } _customEntityCache.Clear(dbBlock.CustomEntityVersion.CustomEntity.CustomEntityDefinitionCode, dbBlock.CustomEntityVersion.CustomEntity.CustomEntityId); await _messageAggregator.PublishAsync(new CustomEntityVersionBlockUpdatedMessage() { CustomEntityId = dbBlock.CustomEntityVersion.CustomEntityId, CustomEntityDefinitionCode = dbBlock.CustomEntityVersion.CustomEntity.CustomEntityDefinitionCode, CustomEntityVersionBlockId = dbBlock.CustomEntityVersionPageBlockId }); }
public async Task ExecuteAsync(UpdateCustomEntityDraftVersionCommand command, IExecutionContext executionContext) { var definition = _customEntityDefinitionRepository.GetByCode(command.CustomEntityDefinitionCode); var draft = await GetDraftVersionAsync(command); using (var scope = _transactionScopeFactory.Create()) { draft = await CreateDraftIfRequiredAsync(command, draft); await ValidateTitle(command, draft, definition); UpdateDraft(command, draft); await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( CustomEntityVersionEntityDefinition.DefinitionCode, draft.CustomEntityVersionId, command.Model); await _commandExecutor.ExecuteAsync(dependencyCommand); scope.Complete(); } _customEntityCache.Clear(command.CustomEntityDefinitionCode, command.CustomEntityId); await _messageAggregator.PublishAsync(new CustomEntityDraftVersionUpdatedMessage() { CustomEntityId = command.CustomEntityId, CustomEntityDefinitionCode = command.CustomEntityDefinitionCode, CustomEntityVersionId = draft.CustomEntityVersionId }); if (command.Publish) { using (var scope = _transactionScopeFactory.Create()) { await _commandExecutor.ExecuteAsync(new PublishCustomEntityCommand(draft.CustomEntityId)); scope.Complete(); } } }
public async Task ExecuteAsync(AddCustomEntityVersionPageModuleCommand command, IExecutionContext executionContext) { var customEntityVersion = _dbContext .CustomEntityVersions .Include(s => s.CustomEntityVersionPageModules) .Include(s => s.CustomEntity) .FirstOrDefault(v => v.CustomEntityVersionId == command.CustomEntityVersionId); EntityNotFoundException.ThrowIfNull(customEntityVersion, command.CustomEntityVersionId); _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(customEntityVersion.CustomEntity.CustomEntityDefinitionCode); if (customEntityVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page modules cannot be deleted unless the entity is in draft status"); } var templateSectionSection = await _dbContext .PageTemplateSections .FirstOrDefaultAsync(l => l.PageTemplateSectionId == command.PageTemplateSectionId); EntityNotFoundException.ThrowIfNull(templateSectionSection, command.PageTemplateSectionId); var customEntityVersionModules = customEntityVersion .CustomEntityVersionPageModules .Where(m => m.PageTemplateSectionId == templateSectionSection.PageTemplateSectionId); CustomEntityVersionPageModule adjacentItem = null; if (command.AdjacentVersionModuleId.HasValue) { adjacentItem = customEntityVersionModules .SingleOrDefault(m => m.CustomEntityVersionPageModuleId == command.AdjacentVersionModuleId); EntityNotFoundException.ThrowIfNull(adjacentItem, command.AdjacentVersionModuleId); } var newModule = new CustomEntityVersionPageModule(); newModule.PageTemplateSection = templateSectionSection; await _pageModuleCommandHelper.UpdateModelAsync(command, newModule); newModule.CustomEntityVersion = customEntityVersion; _entityOrderableHelper.SetOrderingForInsert(customEntityVersionModules, newModule, command.InsertMode, adjacentItem); _dbContext.CustomEntityVersionPageModules.Add(newModule); using (var scope = _transactionScopeFactory.Create()) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( CustomEntityVersionPageModuleEntityDefinition.DefinitionCode, newModule.CustomEntityVersionPageModuleId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand); scope.Complete(); } _customEntityCache.Clear(customEntityVersion.CustomEntity.CustomEntityDefinitionCode, customEntityVersion.CustomEntityId); command.OutputCustomEntityVersionId = newModule.CustomEntityVersionPageModuleId; await _messageAggregator.PublishAsync(new CustomEntityVersionModuleAddedMessage() { CustomEntityId = customEntityVersion.CustomEntityId, CustomEntityVersionPageModuleId = newModule.CustomEntityVersionPageModuleId, CustomEntityDefinitionCode = customEntityVersion.CustomEntity.CustomEntityDefinitionCode }); }
public async Task ExecuteAsync(AddCustomEntityVersionPageBlockCommand command, IExecutionContext executionContext) { var customEntityVersion = _dbContext .CustomEntityVersions .Include(s => s.CustomEntityVersionPageBlocks) .Include(s => s.CustomEntity) .FirstOrDefault(v => v.CustomEntityVersionId == command.CustomEntityVersionId); EntityNotFoundException.ThrowIfNull(customEntityVersion, command.CustomEntityVersionId); _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(customEntityVersion.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext); if (customEntityVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page blocks cannot be added unless the entity is in draft status"); } var page = await _dbContext .Pages .FilterActive() .FilterByPageId(command.PageId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(page, command.PageId); var templateRegion = await _dbContext .PageTemplateRegions .FirstOrDefaultAsync(l => l.PageTemplateRegionId == command.PageTemplateRegionId); EntityNotFoundException.ThrowIfNull(templateRegion, command.PageTemplateRegionId); await ValidateTemplateUsedByPage(command, templateRegion); var customEntityVersionBlocks = customEntityVersion .CustomEntityVersionPageBlocks .Where(m => m.PageTemplateRegionId == templateRegion.PageTemplateRegionId); CustomEntityVersionPageBlock adjacentItem = null; if (command.AdjacentVersionBlockId.HasValue) { adjacentItem = customEntityVersionBlocks .SingleOrDefault(m => m.CustomEntityVersionPageBlockId == command.AdjacentVersionBlockId); EntityNotFoundException.ThrowIfNull(adjacentItem, command.AdjacentVersionBlockId); if (adjacentItem.PageTemplateRegionId != command.PageTemplateRegionId) { throw new Exception("Error adding custom entity page block: the block specified in AdjacentVersionBlockId is in a different region to the block being added."); } } var newBlock = new CustomEntityVersionPageBlock(); newBlock.PageTemplateRegion = templateRegion; newBlock.Page = page; newBlock.CustomEntityVersion = customEntityVersion; await _pageBlockCommandHelper.UpdateModelAsync(command, newBlock); _entityOrderableHelper.SetOrderingForInsert(customEntityVersionBlocks, newBlock, command.InsertMode, adjacentItem); _dbContext.CustomEntityVersionPageBlocks.Add(newBlock); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( CustomEntityVersionPageBlockEntityDefinition.DefinitionCode, newBlock.CustomEntityVersionPageBlockId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand, executionContext); scope.QueueCompletionTask(() => OnTransactionComplete(customEntityVersion, newBlock)); await scope.CompleteAsync(); } command.OutputCustomEntityVersionPageBlockId = newBlock.CustomEntityVersionPageBlockId; }
public async Task ExecuteAsync(UpdatePageVersionModuleCommand command, IExecutionContext executionContext) { var dbModule = await _dbContext .PageVersionModules .Include(m => m.PageModuleTypeTemplate) .Include(m => m.PageModuleType) .Include(m => m.PageVersion) .Where(l => l.PageVersionModuleId == command.PageVersionModuleId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(dbModule, command.PageVersionModuleId); if (dbModule.PageVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page modules cannot be updated unless the page version is in draft status"); } if (command.PageModuleTypeId != dbModule.PageModuleTypeId) { var pageModuleType = await _dbContext .PageModuleTypes .Where(m => m.PageModuleTypeId == command.PageModuleTypeId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(pageModuleType, command.PageModuleTypeId); dbModule.PageModuleType = pageModuleType; } dbModule.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.DataModel); dbModule.UpdateDate = executionContext.ExecutionDate; if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId && command.PageModuleTypeTemplateId.HasValue) { dbModule.PageModuleTypeTemplate = await _dbContext .PageModuleTypeTemplates .SingleOrDefaultAsync(m => m.PageModuleTypeId == dbModule.PageModuleTypeId && m.PageModuleTypeTemplateId == command.PageModuleTypeTemplateId); EntityNotFoundException.ThrowIfNull(dbModule.PageModuleTypeTemplate, command.PageModuleTypeTemplateId); } else if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId) { dbModule.PageModuleTypeTemplate = null; } using (var scope = _transactionScopeFactory.Create()) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( PageVersionModuleEntityDefinition.DefinitionCode, dbModule.PageVersionModuleId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand); scope.Complete(); } _pageCache.Clear(dbModule.PageVersion.PageId); await _messageAggregator.PublishAsync(new PageVersionModuleUpdatedMessage() { PageId = dbModule.PageVersion.PageId, PageVersionModuleId = command.PageVersionModuleId }); }
public async Task ExecuteAsync(AddPageVersionBlockCommand command, IExecutionContext executionContext) { var templateRegion = await _dbContext .PageTemplateRegions .FirstOrDefaultAsync(l => l.PageTemplateRegionId == command.PageTemplateRegionId); EntityNotFoundException.ThrowIfNull(templateRegion, command.PageTemplateRegionId); var pageVersion = _dbContext .PageVersions .Include(s => s.PageVersionBlocks) .FirstOrDefault(v => v.PageVersionId == command.PageVersionId); EntityNotFoundException.ThrowIfNull(pageVersion, command.PageVersionId); if (pageVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page blocks cannot be added unless the page version is in draft status"); } var pageVersionBlocks = pageVersion .PageVersionBlocks .Where(m => m.PageTemplateRegionId == templateRegion.PageTemplateRegionId); PageVersionBlock adjacentItem = null; if (command.AdjacentVersionBlockId.HasValue) { adjacentItem = pageVersionBlocks .SingleOrDefault(m => m.PageVersionBlockId == command.AdjacentVersionBlockId); EntityNotFoundException.ThrowIfNull(adjacentItem, command.AdjacentVersionBlockId); } var newBlock = new PageVersionBlock(); newBlock.PageTemplateRegion = templateRegion; await _pageBlockCommandHelper.UpdateModelAsync(command, newBlock); newBlock.PageVersion = pageVersion; newBlock.UpdateDate = executionContext.ExecutionDate; _entityAuditHelper.SetCreated(newBlock, executionContext); _entityOrderableHelper.SetOrderingForInsert(pageVersionBlocks, newBlock, command.InsertMode, adjacentItem); _dbContext.PageVersionBlocks.Add(newBlock); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( PageVersionBlockEntityDefinition.DefinitionCode, newBlock.PageVersionBlockId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand, executionContext); scope.QueueCompletionTask(() => OnTransactionComplete(pageVersion, newBlock)); await scope.CompleteAsync(); } command.OutputPageBlockId = newBlock.PageVersionBlockId; }
public async Task ExecuteAsync(AddPageVersionModuleCommand command, IExecutionContext executionContext) { var templateSectionSection = await _dbContext .PageTemplateSections .FirstOrDefaultAsync(l => l.PageTemplateSectionId == command.PageTemplateSectionId); EntityNotFoundException.ThrowIfNull(templateSectionSection, command.PageTemplateSectionId); var pageVersion = _dbContext .PageVersions .Include(s => s.PageVersionModules) .FirstOrDefault(v => v.PageVersionId == command.PageVersionId); EntityNotFoundException.ThrowIfNull(pageVersion, command.PageVersionId); if (pageVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft) { throw new NotPermittedException("Page modules cannot be added unless the page version is in draft status"); } var pageVersionModules = pageVersion .PageVersionModules .Where(m => m.PageTemplateSectionId == templateSectionSection.PageTemplateSectionId); PageVersionModule adjacentItem = null; if (command.AdjacentVersionModuleId.HasValue) { adjacentItem = pageVersionModules .SingleOrDefault(m => m.PageVersionModuleId == command.AdjacentVersionModuleId); EntityNotFoundException.ThrowIfNull(adjacentItem, command.AdjacentVersionModuleId); } var newModule = new PageVersionModule(); newModule.PageTemplateSection = templateSectionSection; await _pageModuleCommandHelper.UpdateModelAsync(command, newModule); newModule.PageVersion = pageVersion; newModule.UpdateDate = executionContext.ExecutionDate; _entityAuditHelper.SetCreated(newModule, executionContext); _entityOrderableHelper.SetOrderingForInsert(pageVersionModules, newModule, command.InsertMode, adjacentItem); _dbContext.PageVersionModules.Add(newModule); using (var scope = _transactionScopeFactory.Create()) { await _dbContext.SaveChangesAsync(); var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand( PageVersionModuleEntityDefinition.DefinitionCode, newModule.PageVersionModuleId, command.DataModel); await _commandExecutor.ExecuteAsync(dependencyCommand); scope.Complete(); } _pageCache.Clear(pageVersion.PageId); command.OutputPageModuleId = newModule.PageVersionModuleId; await _messageAggregator.PublishAsync(new PageVersionModuleAddedMessage() { PageId = pageVersion.PageId, PageVersionModuleId = newModule.PageVersionModuleId }); }