public async Task ExecuteAsync(DeleteDocumentAssetCommand command, IExecutionContext executionContext)
        {
            var documentAsset = await _dbContext
                                .DocumentAssets
                                .FilterById(command.DocumentAssetId)
                                .SingleOrDefaultAsync();

            if (documentAsset != null)
            {
                await _dependableEntityDeleteCommandValidator.ValidateAsync(DocumentAssetEntityDefinition.DefinitionCode, documentAsset.DocumentAssetId, executionContext);

                var deleteFileCommand = new QueueAssetFileDeletionCommand()
                {
                    EntityDefinitionCode = DocumentAssetEntityDefinition.DefinitionCode,
                    FileNameOnDisk       = documentAsset.FileNameOnDisk,
                    FileExtension        = documentAsset.FileExtension
                };
                _dbContext.DocumentAssets.Remove(documentAsset);

                using (var scope = _transactionScopeFactory.Create(_dbContext))
                {
                    await _dbContext.SaveChangesAsync();

                    await _commandExecutor.ExecuteAsync(deleteFileCommand, executionContext);

                    scope.QueueCompletionTask(() => OnTransactionComplete(command));
                    await scope.CompleteAsync();
                }
            }
        }
        public async Task ExecuteAsync(DeletePageCommand command, IExecutionContext executionContext)
        {
            var page = await _dbContext
                       .Pages
                       .FilterById(command.PageId)
                       .SingleOrDefaultAsync();

            if (page == null)
            {
                return;
            }

            var pageRoute = await _queryExecutor.ExecuteAsync(new GetPageRouteByIdQuery(page.PageId), executionContext);

            EntityNotFoundException.ThrowIfNull(pageRoute, command.PageId);

            await _dependableEntityDeleteCommandValidator.ValidateAsync(PageEntityDefinition.DefinitionCode, command.PageId, executionContext);

            _dbContext.Pages.Remove(page);

            using (var scope = _transactionScopeFactory.Create(_dbContext))
            {
                await _dbContext.SaveChangesAsync();

                await _pageStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.PageId);

                scope.QueueCompletionTask(() => OnTransactionComplete(pageRoute));
                await scope.CompleteAsync();
            }
        }
Exemplo n.º 3
0
        public async Task ExecuteAsync(DeleteUnstructuredDataDependenciesCommand command, IExecutionContext executionContext)
        {
            await _dependableEntityDeleteCommandValidator.ValidateAsync(command.RootEntityDefinitionCode, command.RootEntityId, executionContext);

            await _entityFrameworkSqlExecutor
            .ExecuteCommandAsync(_dbContext,
                                 "Cofoundry.UnstructuredDataDependency_Delete",
                                 new SqlParameter("EntityDefinitionCode", command.RootEntityDefinitionCode),
                                 new SqlParameter("EntityId", command.RootEntityId)
                                 );
        }
        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);
                await _dependableEntityDeleteCommandValidator.ValidateAsync(customEntity.CustomEntityDefinitionCode, command.CustomEntityId, executionContext);

                _dbContext.CustomEntities.Remove(customEntity);

                using (var scope = _transactionScopeFactory.Create(_dbContext))
                {
                    await _dbContext.SaveChangesAsync();

                    await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId);

                    scope.QueueCompletionTask(() => OnTransactionComplete(command, customEntity));
                    await scope.CompleteAsync();
                }
            }
        }