public void SetSettingProperty <TCommand, TCommandProperty>(
            TCommand source,
            Expression <Func <TCommand, TCommandProperty> > propertyLambda,
            List <Setting> allSettings,
            IExecutionContext executionContext)
        {
            Type type = typeof(TCommand);

            var member   = propertyLambda.Body as MemberExpression;
            var propInfo = member.Member as PropertyInfo;

            var setting = allSettings.SingleOrDefault(s => s.SettingKey == propInfo.Name);

            // Create the setting if it does not exist
            if (setting == null)
            {
                setting            = new Setting();
                setting.SettingKey = propInfo.Name;
                setting.CreateDate = executionContext.ExecutionDate;
                setting.UpdateDate = executionContext.ExecutionDate;
                _dbContext.Settings.Add(setting);
            }

            var value           = propInfo.GetValue(source);
            var serializedValue = _dbUnstructuredDataSerializer.Serialize(propInfo.GetValue(source));

            if (setting.SettingValue != serializedValue)
            {
                setting.SettingValue = _dbUnstructuredDataSerializer.Serialize(propInfo.GetValue(source));
                setting.UpdateDate   = executionContext.ExecutionDate;
            }
        }
        private void UpdateDraft(UpdateCustomEntityDraftVersionCommand command, CustomEntityVersion draft)
        {
            EntityNotFoundException.ThrowIfNull(draft, "Draft:" + command.CustomEntityId);

            draft.Title          = command.Title.Trim();
            draft.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.Model);
        }
Exemple #3
0
        private CustomEntity MapEntity(AddCustomEntityCommand command, CustomEntityDefinitionSummary definition, IExecutionContext executionContext)
        {
            var entity = new CustomEntity();

            _entityAuditHelper.SetCreated(entity, executionContext);

            entity.Locale  = GetLocale(command.LocaleId);
            entity.UrlSlug = command.UrlSlug;
            entity.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode;

            var version = new CustomEntityVersion();

            version.Title          = command.Title.Trim();
            version.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.Model);
            version.DisplayVersion = 1;

            if (command.Publish)
            {
                entity.PublishStatusCode = PublishStatusCode.Published;
                entity.PublishDate       = command.PublishDate ?? executionContext.ExecutionDate;
                version.WorkFlowStatusId = (int)WorkFlowStatus.Published;
            }
            else
            {
                entity.PublishStatusCode = PublishStatusCode.Unpublished;
                entity.PublishDate       = command.PublishDate;
                version.WorkFlowStatusId = (int)WorkFlowStatus.Draft;
            }

            _entityAuditHelper.SetCreated(version, executionContext);
            entity.CustomEntityVersions.Add(version);

            return(entity);
        }
        public async Task UpdateModelAsync(IPageVersionModuleDataModelCommand command, IEntityVersionPageModule dbModule)
        {
            if (command.PageModuleTypeId != dbModule.PageModuleTypeId)
            {
                var pageTemplateSectionId = dbModule.PageTemplateSection != null ? dbModule.PageTemplateSection.PageTemplateSectionId : dbModule.PageTemplateSectionId;
                var pageModuleType        = await _dbContext
                                            .PageModuleTypes
                                            .Where(m => m.PageModuleTypeId == command.PageModuleTypeId)
                                            .SingleOrDefaultAsync();

                EntityNotFoundException.ThrowIfNull(pageModuleType, command.PageModuleTypeId);
                dbModule.PageModuleType = pageModuleType;
            }

            dbModule.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.DataModel);

            if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId && command.PageModuleTypeTemplateId.HasValue)
            {
                dbModule.PageModuleTypeTemplate = await _dbContext
                                                  .PageModuleTypeTemplates
                                                  .SingleOrDefaultAsync(m => m.PageModuleTypeId == command.PageModuleTypeId && m.PageModuleTypeTemplateId == command.PageModuleTypeTemplateId);

                EntityNotFoundException.ThrowIfNull(dbModule.PageModuleTypeTemplate, command.PageModuleTypeTemplateId);
            }
            else if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId)
            {
                dbModule.PageModuleTypeTemplate = null;
            }
        }
        public async Task ExecuteAsync(UpdatePageVersionBlockCommand command, IExecutionContext executionContext)
        {
            var dbBlock = await _dbContext
                          .PageVersionBlocks
                          .Include(m => m.PageBlockTypeTemplate)
                          .Include(m => m.PageBlockType)
                          .Include(m => m.PageVersion)
                          .Where(l => l.PageVersionBlockId == command.PageVersionBlockId)
                          .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbBlock, command.PageVersionBlockId);

            if (dbBlock.PageVersion.WorkFlowStatusId != (int)WorkFlowStatus.Draft)
            {
                throw new NotPermittedException("Page blocks cannot be updated unless the page version is in draft status");
            }

            if (command.PageBlockTypeId != dbBlock.PageBlockTypeId)
            {
                var pageBlockType = await _dbContext
                                    .PageBlockTypes
                                    .Where(m => m.PageBlockTypeId == command.PageBlockTypeId)
                                    .SingleOrDefaultAsync();

                EntityNotFoundException.ThrowIfNull(pageBlockType, command.PageBlockTypeId);
                dbBlock.PageBlockType = pageBlockType;
            }

            dbBlock.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.DataModel);
            dbBlock.UpdateDate     = executionContext.ExecutionDate;

            if (command.PageBlockTypeTemplateId != dbBlock.PageBlockTypeTemplateId && command.PageBlockTypeTemplateId.HasValue)
            {
                dbBlock.PageBlockTypeTemplate = await _dbContext
                                                .PageBlockTypeTemplates
                                                .SingleOrDefaultAsync(m => m.PageBlockTypeId == dbBlock.PageBlockTypeId && m.PageBlockTypeTemplateId == command.PageBlockTypeTemplateId);

                EntityNotFoundException.ThrowIfNull(dbBlock.PageBlockTypeTemplate, command.PageBlockTypeTemplateId);
            }
            else if (command.PageBlockTypeTemplateId != dbBlock.PageBlockTypeTemplateId)
            {
                dbBlock.PageBlockTypeTemplate = null;
            }

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

                var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand(
                    PageVersionBlockEntityDefinition.DefinitionCode,
                    dbBlock.PageVersionBlockId,
                    command.DataModel);

                await _commandExecutor.ExecuteAsync(dependencyCommand, executionContext);

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

                await scope.CompleteAsync();
            }
        }
        private CustomEntity MapEntity(AddCustomEntityCommand command, CustomEntityDefinitionSummary definition, IExecutionContext executionContext)
        {
            // Create Page
            var entity = new CustomEntity();

            _entityAuditHelper.SetCreated(entity, executionContext);

            entity.Locale  = GetLocale(command.LocaleId);
            entity.UrlSlug = command.UrlSlug;
            entity.CustomEntityDefinitionCode = definition.CustomEntityDefinitionCode;

            var version = new CustomEntityVersion();

            version.Title            = command.Title.Trim();
            version.SerializedData   = _dbUnstructuredDataSerializer.Serialize(command.Model);
            version.WorkFlowStatusId = command.Publish ? (int)WorkFlowStatus.Published : (int)WorkFlowStatus.Draft;

            _entityAuditHelper.SetCreated(version, executionContext);
            entity.CustomEntityVersions.Add(version);

            return(entity);
        }
Exemple #7
0
        public async Task ExecuteAsync(UpdatePageVersionModuleCommand command, IExecutionContext executionContext)
        {
            var dbModule = await _dbContext
                           .PageVersionModules
                           .Include(m => m.PageModuleTypeTemplate)
                           .Include(m => m.PageModuleType)
                           .Include(m => m.PageVersion)
                           .Where(l => l.PageVersionModuleId == command.PageVersionModuleId)
                           .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbModule, command.PageVersionModuleId);

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

            if (command.PageModuleTypeId != dbModule.PageModuleTypeId)
            {
                var pageModuleType = await _dbContext
                                     .PageModuleTypes
                                     .Where(m => m.PageModuleTypeId == command.PageModuleTypeId)
                                     .SingleOrDefaultAsync();

                EntityNotFoundException.ThrowIfNull(pageModuleType, command.PageModuleTypeId);
                dbModule.PageModuleType = pageModuleType;
            }

            dbModule.SerializedData = _dbUnstructuredDataSerializer.Serialize(command.DataModel);
            dbModule.UpdateDate     = executionContext.ExecutionDate;

            if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId && command.PageModuleTypeTemplateId.HasValue)
            {
                dbModule.PageModuleTypeTemplate = await _dbContext
                                                  .PageModuleTypeTemplates
                                                  .SingleOrDefaultAsync(m => m.PageModuleTypeId == dbModule.PageModuleTypeId && m.PageModuleTypeTemplateId == command.PageModuleTypeTemplateId);

                EntityNotFoundException.ThrowIfNull(dbModule.PageModuleTypeTemplate, command.PageModuleTypeTemplateId);
            }
            else if (command.PageModuleTypeTemplateId != dbModule.PageModuleTypeTemplateId)
            {
                dbModule.PageModuleTypeTemplate = null;
            }

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

                var dependencyCommand = new UpdateUnstructuredDataDependenciesCommand(
                    PageVersionModuleEntityDefinition.DefinitionCode,
                    dbModule.PageVersionModuleId,
                    command.DataModel);

                await _commandExecutor.ExecuteAsync(dependencyCommand);

                scope.Complete();
            }
            _pageCache.Clear(dbModule.PageVersion.PageId);

            await _messageAggregator.PublishAsync(new PageVersionModuleUpdatedMessage()
            {
                PageId = dbModule.PageVersion.PageId,
                PageVersionModuleId = command.PageVersionModuleId
            });
        }