Beispiel #1
0
        public async Task ExecuteAsync(AddPageDirectoryCommand command, IExecutionContext executionContext)
        {
            // Custom Validation
            await ValidateIsUniqueAsync(command, executionContext);

            var pageDirectory = new PageDirectory();

            pageDirectory.Name     = command.Name;
            pageDirectory.UrlPath  = command.UrlPath;
            pageDirectory.IsActive = true;
            pageDirectory.ParentPageDirectoryId = command.ParentPageDirectoryId;
            _entityAuditHelper.SetCreated(pageDirectory, executionContext);

            _dbContext.PageDirectories.Add(pageDirectory);
            await _dbContext.SaveChangesAsync();

            _cache.Clear();

            command.OutputPageDirectoryId = pageDirectory.PageDirectoryId;
        }
        public async Task ExecuteAsync(UpdatePageDirectoryCommand command, IExecutionContext executionContext)
        {
            var pageDirectory = await _dbContext
                                .PageDirectories
                                .SingleOrDefaultAsync(w => w.PageDirectoryId == command.PageDirectoryId);

            EntityNotFoundException.ThrowIfNull(pageDirectory, command.PageDirectoryId);

            // Custom Validation
            await ValidateIsUniqueAsync(command, executionContext);
            await ValidateUrlPropertiesAllowedToChange(command, pageDirectory);

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

            await _dbContext.SaveChangesAsync();

            _transactionScopeFactory.QueueCompletionTask(_dbContext, _cache.Clear);
        }
Beispiel #3
0
        public async Task ExecuteAsync(EnsureEntityDefinitionExistsCommand command, IExecutionContext executionContext)
        {
            var entityDefinition = _entityDefinitionRepository.GetByCode(command.EntityDefinitionCode);

            var dbDefinition = await _dbContext
                               .EntityDefinitions
                               .SingleOrDefaultAsync(e => e.EntityDefinitionCode == command.EntityDefinitionCode);

            if (dbDefinition == null)
            {
                dbDefinition = new EntityDefinition()
                {
                    EntityDefinitionCode = entityDefinition.EntityDefinitionCode,
                    Name = entityDefinition.Name
                };

                _dbContext.EntityDefinitions.Add(dbDefinition);
                await _dbContext.SaveChangesAsync();
            }
        }
Beispiel #4
0
        public async Task ExecuteAsync(UpdateCurrentUserAccountCommand command, IExecutionContext executionContext)
        {
            _permissionValidationService.EnforceIsLoggedIn(executionContext.UserContext);
            var userId = executionContext.UserContext.UserId.Value;

            var user = await _dbContext
                       .Users
                       .FilterCanLogIn()
                       .FilterById(userId)
                       .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(user, userId);

            await UpdateEmailAsync(command, userId, user, executionContext);

            user.FirstName = command.FirstName.Trim();
            user.LastName  = command.LastName.Trim();

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

            if (documentAsset != null)
            {
                documentAsset.IsDeleted = true;
                using (var scope = _transactionScopeFactory.Create())
                {
                    await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(DocumentAssetEntityDefinition.DefinitionCode, documentAsset.DocumentAssetId));

                    await _dbContext.SaveChangesAsync();

                    scope.Complete();
                }
            }
        }
Beispiel #6
0
        public async Task ExecuteAsync(UpdateImageAssetCommand command, IExecutionContext executionContext)
        {
            bool hasNewFile = command.File != null;

            var imageAsset = await _dbContext
                             .ImageAssets
                             .Include(a => a.ImageAssetTags)
                             .ThenInclude(a => a.Tag)
                             .FilterById(command.ImageAssetId)
                             .SingleOrDefaultAsync();

            imageAsset.FileDescription       = command.Title;
            imageAsset.FileName              = SlugFormatter.ToSlug(command.Title);
            imageAsset.DefaultAnchorLocation = command.DefaultAnchorLocation;
            _entityTagHelper.UpdateTags(imageAsset.ImageAssetTags, command.Tags, executionContext);
            _entityAuditHelper.SetUpdated(imageAsset, executionContext);

            using (var scope = _transactionScopeFactory.Create(_dbContext))
            {
                if (hasNewFile)
                {
                    await _imageAssetFileService.SaveAsync(command.File, imageAsset, nameof(command.File));
                }

                await _dbContext.SaveChangesAsync();

                scope.Complete();
            }

            if (hasNewFile)
            {
                await _imageAssetFileCache.ClearAsync(imageAsset.ImageAssetId);
            }
            _imageAssetCache.Clear(imageAsset.ImageAssetId);

            await _messageAggregator.PublishAsync(new ImageAssetUpdatedMessage()
            {
                ImageAssetId   = imageAsset.ImageAssetId,
                HasFileChanged = hasNewFile
            });
        }
        public async Task ExecuteAsync(AddCustomEntityCommand command, IExecutionContext executionContext)
        {
            var definition = _queryExecutor.GetById <CustomEntityDefinitionSummary>(command.CustomEntityDefinitionCode);

            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())
            {
                await _dbContext.SaveChangesAsync();

                var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand(
                    CustomEntityVersionEntityDefinition.DefinitionCode,
                    entity.CustomEntityVersions.First().CustomEntityVersionId,
                    command.Model);

                await _commandExecutor.ExecuteAsync(dependencyCommand);

                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
            });
        }
Beispiel #8
0
        public async Task ExecuteAsync(RegisterPageTemplatesCommand command, IExecutionContext executionContext)
        {
            var dbPageTemplates = await _dbContext
                                  .PageTemplates
                                  .Include(t => t.PageTemplateSections)
                                  .ToDictionaryAsync(d => d.FileName);

            var fileTemplates = _pageTemplateViewFileLocator
                                .GetPageTemplateFiles();

            DetectDuplicateTemplates(fileTemplates);

            // Mark removed templates as deleted
            await DeleteTemplates(executionContext, dbPageTemplates, fileTemplates);
            await UpdateTemplates(executionContext, dbPageTemplates, fileTemplates);

            // Save changes
            await _dbContext.SaveChangesAsync();

            _pageCache.Clear();
        }
        public async Task ResetPasswordAsync(User user, IResetUserPasswordCommand command, IExecutionContext executionContext)
        {
            ValidateUserAccountExists(user);
            ValidateUserArea(user.UserAreaCode);

            var existingIncompleteRequests = await QueryIncompleteRequests(user).ToListAsync();

            SetExistingRequestsComplete(existingIncompleteRequests);
            var request = CreateRequest(executionContext, user);

            SetMailTemplate(command, user, request);

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

                await _mailService.SendAsync(user.Email, user.GetFullName(), command.MailTemplate);

                await scope.CompleteAsync();
            }
        }
        public async Task ExecuteAsync(AddPageCommand command, IExecutionContext executionContext)
        {
            // Custom Validation
            ValidateIsPageUnique(command, executionContext);

            var page = await MapPage(command, executionContext);

            _dbContext.Pages.Add(page);
            await _dbContext.SaveChangesAsync();

            _pageCache.ClearRoutes();

            // Set Ouput
            command.OutputPageId = page.PageId;

            await _messageAggregator.PublishAsync(new PageAddedMessage()
            {
                PageId = page.PageId,
                HasPublishedVersionChanged = command.Publish
            });
        }
Beispiel #11
0
        public async Task ExecuteAsync(RegisterPageModuleTypesCommand command, IExecutionContext executionContext)
        {
            var dbPageModules = await _dbContext
                                .PageModuleTypes
                                .Include(t => t.PageModuleTemplates)
                                .ToDictionaryAsync(d => d.FileName);

            DetectDuplicateModules();

            var moduleDataModels = _allPageModuleDataModels
                                   .ToDictionary(m => FormatModuleFileName(m));

            await DeleteModules(executionContext, dbPageModules, moduleDataModels);

            await UpdateModulesAsync(executionContext, dbPageModules, moduleDataModels);

            await _dbContext.SaveChangesAsync();

            _pageCache.Clear();
            _moduleCache.Clear();
        }
Beispiel #12
0
        public async Task ExecuteAsync(AddAuthorizedTaskCommand command, IExecutionContext executionContext)
        {
            var taskTypeDefinition = _authorizedTaskTypeDefinitionRepository.GetRequiredByCode(command.AuthorizedTaskTypeCode);
            var ipAddressId        = await GetCurrentIPAddressIdAsync(executionContext);

            await ValidateRateLimitAsync(ipAddressId, command, taskTypeDefinition, executionContext);

            var user = await GetUserAsync(command);

            var authorizedTask = MapAuthorizedTask(command, taskTypeDefinition, user, ipAddressId, executionContext);

            _dbContext.AuthorizedTasks.Add(authorizedTask);
            await _dbContext.SaveChangesAsync();

            command.OutputAuthorizedTaskId = authorizedTask.AuthorizedTaskId;
            command.OutputToken            = _authorizedTaskTokenFormatter.Format(new AuthorizedTaskTokenParts()
            {
                AuthorizedTaskId  = authorizedTask.AuthorizedTaskId,
                AuthorizationCode = authorizedTask.AuthorizationCode
            });
        }
        public async Task ExecuteAsync(RegisterPageBlockTypesCommand command, IExecutionContext executionContext)
        {
            var dbPageBlockTypes = await _dbContext
                                   .PageBlockTypes
                                   .Include(t => t.PageBlockTemplates)
                                   .ToDictionaryAsync(d => d.FileName);

            DetectDuplicateBlockTypes();

            var blockTypeDataModels = _allPageBlockTypeDataModels
                                      .ToDictionary(m => FormatBlockTypeFileName(m));

            await DeleteBlockTypes(executionContext, dbPageBlockTypes, blockTypeDataModels);

            await UpdateBlocksAsync(executionContext, dbPageBlockTypes, blockTypeDataModels);

            await _dbContext.SaveChangesAsync();

            _transactionScopeFactory.QueueCompletionTask(_dbContext, _pageCache.Clear);
            _transactionScopeFactory.QueueCompletionTask(_dbContext, _blockCache.Clear);
        }
Beispiel #14
0
        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), executionContext);

            // Custom Validation
            ValidateCommand(command, definition);
            await ValidateIsUniqueAsync(command, definition, executionContext);

            var entity = MapEntity(command, definition, executionContext);

            await SetOrdering(entity, definition);

            _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, executionContext);

                await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(entity.CustomEntityId);

                scope.QueueCompletionTask(() => OnTransactionComplete(command, entity));

                await scope.CompleteAsync();
            }

            // Set Ouput
            command.OutputCustomEntityId = entity.CustomEntityId;
        }
Beispiel #15
0
        public async Task ExecuteAsync(AddUserCommand command, IExecutionContext executionContext)
        {
            var userArea   = _userAreaRepository.GetRequiredByCode(command.UserAreaCode);
            var dbUserArea = await GetUserAreaAsync(userArea);

            var role = await GetAndValidateRoleAsync(command, executionContext);

            var user = new User()
            {
                FirstName              = command.FirstName?.Trim(),
                LastName               = command.LastName?.Trim(),
                RequirePasswordChange  = command.RequirePasswordChange,
                LastPasswordChangeDate = executionContext.ExecutionDate,
                AccountVerifiedDate    = command.IsAccountVerified ? executionContext.ExecutionDate : (DateTime?)null,
                CreateDate             = executionContext.ExecutionDate,
                Role          = role,
                UserArea      = dbUserArea,
                CreatorId     = executionContext.UserContext.UserId,
                SecurityStamp = _securityStampGenerator.Generate()
            };

            if (!command.IsActive)
            {
                user.DeactivatedDate = executionContext.ExecutionDate;
            }

            await _userUpdateCommandHelper.UpdateEmailAndUsernameAsync(command.Email, command.Username, user, executionContext);

            await ValidatePasswordAsync(userArea, user, command, executionContext);

            SetPassword(user, command, userArea);
            SetDisplayName(command, user);

            _dbContext.Users.Add(user);
            await _dbContext.SaveChangesAsync();

            await _transactionScopeFactory.QueueCompletionTaskAsync(_dbContext, () => OnTransactionComplete(userArea, user));

            command.OutputUserId = user.UserId;
        }
Beispiel #16
0
        public async Task ExecuteAsync(UnPublishPageCommand command, IExecutionContext executionContext)
        {
            var page = await _dbContext
                       .Pages
                       .FilterActive()
                       .FilterByPageId(command.PageId)
                       .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(page, command.PageId);

            if (page.PublishStatusCode == PublishStatusCode.Unpublished)
            {
                // No action
                return;
            }

            var version = await _dbContext
                          .PageVersions
                          .Include(p => p.Page)
                          .FilterActive()
                          .FilterByPageId(command.PageId)
                          .OrderByLatest()
                          .FirstOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(version, command.PageId);

            page.PublishStatusCode   = PublishStatusCode.Unpublished;
            version.WorkFlowStatusId = (int)WorkFlowStatus.Draft;

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

                await _pageStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.PageId);

                scope.QueueCompletionTask(() => OnTransactionComplete(command));

                await scope.CompleteAsync();
            }
        }
        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.QueueCompletionTask(() => OnTransactionComplete(customEntity));

                await scope.CompleteAsync();
            }
        }
        public async Task ExecuteAsync(DeletePageVersionModuleCommand command, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .PageVersionModules
                           .Where(p => p.PageVersionModuleId == command.PageVersionModuleId)
                           .Select(p => new
            {
                Module           = p,
                PageId           = p.PageVersion.PageId,
                WorkFlowStatusId = p.PageVersion.WorkFlowStatusId
            })
                           .SingleOrDefaultAsync();

            if (dbResult != null)
            {
                if (dbResult.WorkFlowStatusId != (int)WorkFlowStatus.Draft)
                {
                    throw new NotPermittedException("Page modules cannot be deleted unless the page version is in draft status");
                }

                var versionId = dbResult.Module.PageVersionId;
                using (var scope = _transactionScopeFactory.Create())
                {
                    await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(PageVersionModuleEntityDefinition.DefinitionCode, dbResult.Module.PageVersionModuleId));

                    _dbContext.PageVersionModules.Remove(dbResult.Module);
                    await _dbContext.SaveChangesAsync();

                    scope.Complete();
                }
                _pageCache.Clear(dbResult.PageId);

                await _messageAggregator.PublishAsync(new PageVersionModuleDeletedMessage()
                {
                    PageId        = dbResult.PageId,
                    PageVersionId = versionId
                });
            }
        }
Beispiel #19
0
        public async Task ExecuteAsync(DeleteImageAssetCommand command, IExecutionContext executionContext)
        {
            var imageAsset = await _dbContext
                             .ImageAssets
                             .FilterById(command.ImageAssetId)
                             .SingleOrDefaultAsync();

            if (imageAsset != null)
            {
                imageAsset.IsDeleted = true;
                using (var scope = _transactionScopeFactory.Create(_dbContext))
                {
                    await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(ImageAssetEntityDefinition.DefinitionCode, imageAsset.ImageAssetId), executionContext);

                    await _dbContext.SaveChangesAsync();

                    scope.QueueCompletionTask(() => OnTransactionComplete(command));

                    await scope.CompleteAsync();
                }
            }
        }
Beispiel #20
0
        public async Task ExecuteAsync(CompleteUserPasswordResetCommand command, IExecutionContext executionContext)
        {
            var validationResult = await _queryExecutor.ExecuteAsync(CreateValidationQuery(command));

            ValidatePasswordRequest(validationResult);

            var request = await QueryPasswordRequestIfToken(command).SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(request, command.UserPasswordResetRequestId);

            UpdatePasswordAndSetComplete(request, command, executionContext);
            SetMailTemplate(command, request.User);

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

                await _mailService.SendAsync(request.User.Email, request.User.GetFullName(), command.MailTemplate);

                scope.Complete();
            }
        }
        public async Task ExecuteAsync(UpdatePageUrlCommand command, IExecutionContext executionContext)
        {
            var page = await _dbContext
                       .Pages
                       .Include(p => p.Locale)
                       .Include(p => p.PageDirectory)
                       .FilterActive()
                       .FilterByPageId(command.PageId)
                       .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(page, command.PageId);

            await ValidateIsPageUniqueAsync(command, page, executionContext);

            await MapPageAsync(command, executionContext, page);

            var isPublished = page.PublishStatusCode == PublishStatusCode.Published;

            await _dbContext.SaveChangesAsync();

            await _transactionScopeFactory.QueueCompletionTaskAsync(_dbContext, () => OnTransactionComplete(command, isPublished));
        }
Beispiel #22
0
        public async Task ExecuteAsync(UpdateCurrentUserCommand command, IExecutionContext executionContext)
        {
            _permissionValidationService.EnforceIsSignedIn(executionContext.UserContext);
            var userId = executionContext.UserContext.UserId.Value;

            var user = await _dbContext
                       .Users
                       .FilterCanSignIn()
                       .FilterById(userId)
                       .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(user, userId);

            var updateResult = await _userUpdateCommandHelper.UpdateEmailAndUsernameAsync(command.Email, command.Username, user, executionContext);

            UpdateName(command, user);
            user.FirstName = command.FirstName?.Trim();
            user.LastName  = command.LastName?.Trim();

            if (updateResult.HasUpdate())
            {
                _userSecurityStampUpdateHelper.Update(user);
            }

            using (var scope = _domainRepository.Transactions().CreateScope())
            {
                await _dbContext.SaveChangesAsync();

                // Here we could assume that reset requests only need invalidating if the contact email changes, but if the
                // user is updating their account details, then we could also assume that old requests are stale anyway.
                await _domainRepository
                .WithContext(executionContext)
                .ExecuteCommandAsync(new InvalidateAuthorizedTaskBatchCommand(userId, UserAccountRecoveryAuthorizedTaskType.Code));

                scope.QueueCompletionTask(() => OnTransactionComplete(user, updateResult));
                await scope.CompleteAsync();
            }
        }
        public async Task ExecuteAsync(AddImageAssetCommand command, IExecutionContext executionContext)
        {
            ValidateFileType(command);

            var imageAsset = new ImageAsset();

            imageAsset.Title    = command.Title;
            imageAsset.FileName = SlugFormatter.ToSlug(command.Title);
            imageAsset.DefaultAnchorLocation = command.DefaultAnchorLocation;
            imageAsset.FileUpdateDate        = executionContext.ExecutionDate;
            imageAsset.FileNameOnDisk        = "file-not-saved";
            imageAsset.FileExtension         = "unknown";
            imageAsset.VerificationToken     = _randomStringGenerator.Generate(6);

            var fileStamp = AssetFileStampHelper.ToFileStamp(imageAsset.FileUpdateDate);

            _entityTagHelper.UpdateTags(imageAsset.ImageAssetTags, command.Tags, executionContext);
            _entityAuditHelper.SetCreated(imageAsset, executionContext);

            _dbContext.ImageAssets.Add(imageAsset);

            using (var scope = _transactionScopeFactory.Create(_dbContext))
            {
                // Save first to get an Id
                await _dbContext.SaveChangesAsync();

                // Update the disk filename
                imageAsset.FileNameOnDisk = $"{imageAsset.ImageAssetId}-{fileStamp}";

                await _imageAssetFileService.SaveAsync(command.File, imageAsset, nameof(command.File));

                command.OutputImageAssetId = imageAsset.ImageAssetId;

                scope.QueueCompletionTask(() => OnTransactionComplete(imageAsset));

                await scope.CompleteAsync();
            }
        }
Beispiel #24
0
        public async Task ExecuteAsync(DeleteCustomEntityVersionPageBlockCommand command, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .CustomEntityVersionPageBlocks
                           .Where(m => m.CustomEntityVersionPageBlockId == command.CustomEntityVersionPageBlockId)
                           .Select(m => new
            {
                Block                      = m,
                CustomEntityId             = m.CustomEntityVersion.CustomEntityId,
                CustomEntityDefinitionCode = m.CustomEntityVersion.CustomEntity.CustomEntityDefinitionCode,
                WorkFlowStatusId           = m.CustomEntityVersion.WorkFlowStatusId
            })
                           .SingleOrDefaultAsync();

            if (dbResult != null)
            {
                _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(dbResult.CustomEntityDefinitionCode, executionContext.UserContext);

                if (dbResult.WorkFlowStatusId != (int)WorkFlowStatus.Draft)
                {
                    throw new NotPermittedException("Page blocks cannot be deleted unless the entity is in draft status");
                }

                var customEntityVersionBlockId = dbResult.Block.CustomEntityVersionPageBlockId;

                using (var scope = _transactionScopeFactory.Create(_dbContext))
                {
                    await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(CustomEntityVersionPageBlockEntityDefinition.DefinitionCode, dbResult.Block.CustomEntityVersionPageBlockId), executionContext);

                    _dbContext.CustomEntityVersionPageBlocks.Remove(dbResult.Block);
                    await _dbContext.SaveChangesAsync();

                    scope.QueueCompletionTask(() => OnTransactionComplete(dbResult.CustomEntityDefinitionCode, dbResult.CustomEntityId, customEntityVersionBlockId));

                    await scope.CompleteAsync();
                }
            }
        }
Beispiel #25
0
        public async Task ExecuteAsync(MarkAsSetUpCommand command, IExecutionContext executionContext)
        {
            _permissionValidationService.EnforceIsSuperAdminRole(executionContext.UserContext);

            var setting = await _dbContext
                          .Settings
                          .SingleOrDefaultAsync(s => s.SettingKey == SETTING_KEY);

            if (setting == null)
            {
                setting            = new Setting();
                setting.SettingKey = SETTING_KEY;
                setting.CreateDate = executionContext.ExecutionDate;
                setting.UpdateDate = executionContext.ExecutionDate;
                _dbContext.Settings.Add(setting);
            }

            setting.SettingValue = "true";

            await _dbContext.SaveChangesAsync();

            _transactionScopeFactory.QueueCompletionTask(_dbContext, _settingCache.Clear);
        }
Beispiel #26
0
        public async Task ExecuteAsync(UpdateCustomEntityUrlCommand command, IExecutionContext executionContext)
        {
            var entity = await _dbContext
                         .CustomEntities
                         .Where(e => e.CustomEntityId == command.CustomEntityId)
                         .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(entity, command.CustomEntityId);
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdateUrlPermission>(entity.CustomEntityDefinitionCode, executionContext.UserContext);

            var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(entity.CustomEntityDefinitionCode);
            var definition      = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext);

            EntityNotFoundException.ThrowIfNull(definition, entity.CustomEntityDefinitionCode);

            await ValidateIsUniqueAsync(command, definition, executionContext);

            Map(command, entity, definition);

            await _dbContext.SaveChangesAsync();

            await _transactionScopeFactory.QueueCompletionTaskAsync(_dbContext, () => OnTransactionComplete(entity));
        }
        public async Task ExecuteAsync(AddPageCommand command, IExecutionContext executionContext)
        {
            // Custom Validation
            await ValidateIsPageUniqueAsync(command, executionContext);

            var page = await MapPage(command, executionContext);

            _dbContext.Pages.Add(page);

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

                await _pageStoredProcedures.UpdatePublishStatusQueryLookupAsync(page.PageId);

                scope.QueueCompletionTask(() => OnTransactionComplete(command, page));

                await scope.CompleteAsync();
            }

            // Set Ouput
            command.OutputPageId = page.PageId;
        }
Beispiel #28
0
        public async Task ExecuteAsync(RegisterPageTemplatesCommand command, IExecutionContext executionContext)
        {
            var dbPageTemplates = (await _dbContext
                                   .PageTemplates
                                   .Include(t => t.PageTemplateRegions)
                                   .ToListAsync())
                                  .ToLookup(d => d.FileName);

            var fileTemplates = _pageTemplateViewFileLocator
                                .GetPageTemplateFiles()
                                .ToList();

            DetectDuplicateTemplates(fileTemplates);

            // Mark removed templates as deleted
            await DeleteTemplates(executionContext, dbPageTemplates, fileTemplates);
            await UpdateTemplates(executionContext, dbPageTemplates, fileTemplates);

            // Save changes
            await _dbContext.SaveChangesAsync();

            _transactionScopeFactory.QueueCompletionTask(_dbContext, _pageCache.Clear);
        }
        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);
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(dbBlock.CustomEntityVersion.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext);

            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, executionContext);

                scope.QueueCompletionTask(() => OnTransactionComplete(dbBlock));

                await scope.CompleteAsync();
            }
        }
Beispiel #30
0
        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)
            {
                await _permissionValidationService.EnforceCustomEntityPermissionAsync <CustomEntityUpdatePermission>(draft.CustomEntity.CustomEntityDefinitionCode);

                var definitionCode = draft.CustomEntity.CustomEntityDefinitionCode;
                var versionId      = draft.CustomEntityVersionId;

                using (var scope = _transactionScopeFactory.Create(_dbContext))
                {
                    await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(CustomEntityVersionEntityDefinition.DefinitionCode, draft.CustomEntityVersionId));

                    _dbContext.CustomEntityVersions.Remove(draft);
                    await _dbContext.SaveChangesAsync();

                    await _customEntityStoredProcedures.UpdatePublishStatusQueryLookupAsync(command.CustomEntityId);

                    scope.Complete();
                }
                _customEntityCache.Clear(definitionCode, command.CustomEntityId);

                await _messageAggregator.PublishAsync(new CustomEntityDraftVersionDeletedMessage()
                {
                    CustomEntityId             = command.CustomEntityId,
                    CustomEntityDefinitionCode = definitionCode,
                    CustomEntityVersionId      = versionId
                });
            }
        }