コード例 #1
0
        public async Task ExecuteAsync(DeleteWebDirectoryCommand command, IExecutionContext executionContext)
        {
            var webDirectory = await _dbContext
                               .WebDirectories
                               .Include(w => w.ChildWebDirectories)
                               .SingleOrDefaultAsync(w => w.WebDirectoryId == command.WebDirectoryId);

            if (webDirectory != null)
            {
                if (!webDirectory.ParentWebDirectoryId.HasValue)
                {
                    throw new ValidationException("Cannot delete the root web directory.");
                }

                webDirectory.IsActive = false;

                using (var scope = _transactionScopeFactory.Create())
                {
                    await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(WebDirectoryEntityDefinition.DefinitionCode, webDirectory.WebDirectoryId));

                    await _dbContext.SaveChangesAsync();

                    scope.Complete();
                }
                _cache.Clear();
            }
        }
コード例 #2
0
        public async Task ExecuteAsync(DeleteWebDirectoryCommand command, IExecutionContext executionContext)
        {
            var webDirectory = await _dbContext
                               .WebDirectories
                               .Include(w => w.ChildWebDirectories)
                               .SingleOrDefaultAsync(w => w.WebDirectoryId == command.WebDirectoryId);

            EntityNotFoundException.ThrowIfNull(webDirectory, command.WebDirectoryId);

            if (!webDirectory.ParentWebDirectoryId.HasValue)
            {
                throw new ValidationException("Cannot delete the root web directory.");
            }
            webDirectory.IsActive = false;

            await _dbContext.SaveChangesAsync();

            _cache.Clear();
        }
コード例 #3
0
        public async Task ExecuteAsync(UpdateWebDirectoryCommand command, IExecutionContext executionContext)
        {
            var webDirectory = await _dbContext
                               .WebDirectories
                               .SingleOrDefaultAsync(w => w.WebDirectoryId == command.WebDirectoryId);

            EntityNotFoundException.ThrowIfNull(webDirectory, command.WebDirectoryId);

            // Custom Validation
            await ValidateIsUnique(command);
            await ValidateUrlPropertiesAllowedToChange(command, webDirectory);

            webDirectory.Name    = command.Name;
            webDirectory.UrlPath = command.UrlPath;
            webDirectory.ParentWebDirectoryId = command.ParentWebDirectoryId;

            await _dbContext.SaveChangesAsync();

            _cache.Clear();
        }
コード例 #4
0
        public async Task ExecuteAsync(AddWebDirectoryCommand command, IExecutionContext executionContext)
        {
            // Custom Validation
            await ValidateIsUnique(command);

            var webDirectory = new WebDirectory();

            webDirectory.Name                 = command.Name;
            webDirectory.UrlPath              = command.UrlPath;
            webDirectory.IsActive             = true;
            webDirectory.ParentWebDirectoryId = command.ParentWebDirectoryId;
            _entityAuditHelper.SetCreated(webDirectory, executionContext);

            _dbContext.WebDirectories.Add(webDirectory);
            await _dbContext.SaveChangesAsync();

            _cache.Clear();

            command.OutputWebDirectoryId = webDirectory.WebDirectoryId;
        }