public async Task ExecuteAsync(DeleteCustomEntityCommand command, IExecutionContext executionContext) { var customEntity = await _dbContext .CustomEntities .SingleOrDefaultAsync(p => p.CustomEntityId == command.CustomEntityId); if (customEntity != null) { _permissionValidationService.EnforceCustomEntityPermission <CustomEntityDeletePermission>(customEntity.CustomEntityDefinitionCode, executionContext.UserContext); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(customEntity.CustomEntityDefinitionCode, customEntity.CustomEntityId), executionContext); _dbContext.CustomEntities.Remove(customEntity); await _dbContext.SaveChangesAsync(); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId); scope.QueueCompletionTask(() => OnTransactionComplete(command, customEntity)); await scope.CompleteAsync(); } } }
public async Task ExecuteAsync(DeleteCustomEntityCommand command, IExecutionContext executionContext) { var customEntity = await _dbContext .CustomEntities .SingleOrDefaultAsync(p => p.CustomEntityId == command.CustomEntityId); if (customEntity != null) { await _permissionValidationService.EnforceCustomEntityPermissionAsync <CustomEntityDeletePermission>(customEntity.CustomEntityDefinitionCode); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(customEntity.CustomEntityDefinitionCode, customEntity.CustomEntityId), executionContext); _dbContext.CustomEntities.Remove(customEntity); await _dbContext.SaveChangesAsync(); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId); scope.Complete(); } _customEntityCache.Clear(customEntity.CustomEntityDefinitionCode, command.CustomEntityId); await _messageAggregator.PublishAsync(new CustomEntityDeletedMessage() { CustomEntityId = command.CustomEntityId, CustomEntityDefinitionCode = customEntity.CustomEntityDefinitionCode }); } }
public async Task ExecuteAsync(DeleteCustomEntityDraftVersionCommand command, IExecutionContext executionContext) { var draft = await _dbContext .CustomEntityVersions .Include(v => v.CustomEntity) .SingleOrDefaultAsync(v => v.CustomEntityId == command.CustomEntityId && v.WorkFlowStatusId == (int)WorkFlowStatus.Draft); if (draft != null) { _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(draft.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext); var definitionCode = draft.CustomEntity.CustomEntityDefinitionCode; var versionId = draft.CustomEntityVersionId; using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(CustomEntityVersionEntityDefinition.DefinitionCode, draft.CustomEntityVersionId), executionContext); _dbContext.CustomEntityVersions.Remove(draft); await _dbContext.SaveChangesAsync(); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId); scope.QueueCompletionTask(() => OnTransactionComplete(command, definitionCode, versionId)); await scope.CompleteAsync(); } } }
public async Task ExecuteAsync(PublishCustomEntityCommand command, IExecutionContext executionContext) { // Prefer draft, but update published entity if no draft (only one draft permitted) var version = await _dbContext .CustomEntityVersions .Include(v => v.CustomEntity) .Where(v => v.CustomEntityId == command.CustomEntityId && (v.WorkFlowStatusId == (int)WorkFlowStatus.Draft || v.WorkFlowStatusId == (int)WorkFlowStatus.Published)) .OrderByDescending(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft) .ThenByDescending(v => v.CreateDate) .FirstOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(version, command.CustomEntityId); var definition = _customEntityDefinitionRepository.GetByCode(version.CustomEntity.CustomEntityDefinitionCode); EntityNotFoundException.ThrowIfNull(definition, version.CustomEntity.CustomEntityDefinitionCode); await _permissionValidationService.EnforceCustomEntityPermissionAsync <CustomEntityPublishPermission>(definition.CustomEntityDefinitionCode); UpdatePublishDate(command, executionContext, version); if (version.WorkFlowStatusId == (int)WorkFlowStatus.Published) { // only thing we can do with a published version is update the date await _dbContext.SaveChangesAsync(); } else { await ValidateTitle(version, definition); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await UpdateUrlSlugIfRequired(version, definition); version.WorkFlowStatusId = (int)WorkFlowStatus.Published; version.CustomEntity.PublishStatusCode = PublishStatusCode.Published; await _dbContext.SaveChangesAsync(); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId); scope.Complete(); } } _customEntityCache.Clear(version.CustomEntity.CustomEntityDefinitionCode, command.CustomEntityId); await _messageAggregator.PublishAsync(new CustomEntityPublishedMessage() { CustomEntityId = command.CustomEntityId, CustomEntityDefinitionCode = version.CustomEntity.CustomEntityDefinitionCode }); }
public async Task ExecuteAsync(UnPublishCustomEntityCommand command, IExecutionContext executionContext) { var customEntity = await _dbContext .CustomEntities .Where(p => p.CustomEntityId == command.CustomEntityId) .SingleOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(customEntity, command.CustomEntityId); _permissionValidationService.EnforceCustomEntityPermission <CustomEntityPublishPermission>(customEntity.CustomEntityDefinitionCode, executionContext.UserContext); if (customEntity.PublishStatusCode == PublishStatusCode.Unpublished) { // No action return; } var version = await _dbContext .CustomEntityVersions .Include(v => v.CustomEntity) .Where(v => v.CustomEntityId == command.CustomEntityId && (v.WorkFlowStatusId == (int)WorkFlowStatus.Draft || v.WorkFlowStatusId == (int)WorkFlowStatus.Published)) .OrderByDescending(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft) .ThenByDescending(v => v.CreateDate) .FirstOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(version, command.CustomEntityId); customEntity.PublishStatusCode = PublishStatusCode.Unpublished; version.WorkFlowStatusId = (int)WorkFlowStatus.Draft; using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _dbContext.SaveChangesAsync(); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId); scope.Complete(); } _customEntityCache.Clear(customEntity.CustomEntityDefinitionCode, command.CustomEntityId); await _messageAggregator.PublishAsync(new CustomEntityUnPublishedMessage() { CustomEntityId = command.CustomEntityId, CustomEntityDefinitionCode = customEntity.CustomEntityDefinitionCode }); }
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(PublishCustomEntityCommand command, IExecutionContext executionContext) { // Prefer draft, but update published entity if no draft (only one draft permitted) var version = await _dbContext .CustomEntityVersions .Include(v => v.CustomEntity) .Where(v => v.CustomEntityId == command.CustomEntityId && (v.WorkFlowStatusId == (int)WorkFlowStatus.Draft || v.WorkFlowStatusId == (int)WorkFlowStatus.Published)) .OrderByDescending(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft) .ThenByDescending(v => v.CreateDate) .FirstOrDefaultAsync(); EntityNotFoundException.ThrowIfNull(version, command.CustomEntityId); var definition = _customEntityDefinitionRepository.GetRequiredByCode(version.CustomEntity.CustomEntityDefinitionCode); _permissionValidationService.EnforceCustomEntityPermission <CustomEntityPublishPermission>(definition.CustomEntityDefinitionCode, executionContext.UserContext); var hasEntityPublishStatusChanged = version.CustomEntity.SetPublished(executionContext.ExecutionDate, command.PublishDate); if (version.WorkFlowStatusId == (int)WorkFlowStatus.Published && !hasEntityPublishStatusChanged) { // only thing we can do with a published version is update the date await _dbContext.SaveChangesAsync(); await _transactionScopeFactory.QueueCompletionTaskAsync(_dbContext, () => OnTransactionComplete(version)); } else { await ValidateTitleAsync(version, definition, executionContext); using (var scope = _transactionScopeFactory.Create(_dbContext)) { await UpdateUrlSlugIfRequiredAsync(version, definition, executionContext); version.WorkFlowStatusId = (int)WorkFlowStatus.Published; await _dbContext.SaveChangesAsync(); await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId); scope.QueueCompletionTask(() => OnTransactionComplete(version)); await scope.CompleteAsync(); } } }