Beispiel #1
0
        public async Task ExecuteAsync(AddPageDirectoryCommand command, IExecutionContext executionContext)
        {
            Normalize(command);
            var parentDirectory = await GetParentDirectoryAsync(command);

            await ValidateIsUniqueAsync(command, executionContext);

            var pageDirectory = new PageDirectory();

            pageDirectory.Name                = command.Name;
            pageDirectory.UrlPath             = command.UrlPath;
            pageDirectory.ParentPageDirectory = parentDirectory;
            _entityAuditHelper.SetCreated(pageDirectory, executionContext);

            _dbContext.PageDirectories.Add(pageDirectory);

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

                await _pageDirectoryStoredProcedures.UpdatePageDirectoryClosureAsync();

                scope.QueueCompletionTask(() => OnTransactionComplete(pageDirectory.PageDirectoryId));
                await scope.CompleteAsync();
            }

            command.OutputPageDirectoryId = pageDirectory.PageDirectoryId;
        }
        public async Task ExecuteAsync(UpdatePageDirectoryUrlCommand command, IExecutionContext executionContext)
        {
            Normalize(command);

            var pageDirectory = await _dbContext
                                .PageDirectories
                                .FilterById(command.PageDirectoryId)
                                .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(pageDirectory, command.PageDirectoryId);

            command.UrlPath = command.UrlPath.ToLowerInvariant();
            var changedPathProps = GetChangedPathProperties(command, pageDirectory).ToArray();

            if (!changedPathProps.Any())
            {
                return;
            }

            await ValidateIsUniqueAsync(command, executionContext);

            var affectedDirectories = await GetAffectedDirectoriesAsync(command);

            ValidateParentDirectory(command, affectedDirectories.Keys);
            var affectedPages = await GetAffectedPagesAndValidatePermissionsAsync(affectedDirectories.Keys, executionContext);

            pageDirectory.UrlPath = command.UrlPath;
            pageDirectory.ParentPageDirectoryId = command.ParentPageDirectoryId;

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

                if (changedPathProps.Contains(nameof(command.ParentPageDirectoryId)))
                {
                    await _pageDirectoryStoredProcedures.UpdatePageDirectoryClosureAsync();
                }
                else if (changedPathProps.Contains(nameof(command.UrlPath)))
                {
                    await _pageDirectoryStoredProcedures.UpdatePageDirectoryPathAsync();
                }

                scope.QueueCompletionTask(() => OnTransactionComplete(affectedDirectories.Values, affectedPages));
                await scope.CompleteAsync();
            }
        }