protected Task On(DisableField command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <SchemaDomainObject>(context, s =>
            {
                GuardSchemaField.CanDisable(s.Snapshot.SchemaDef, command);

                s.DisableField(command);
            }));
        }
Beispiel #2
0
        protected Task On(ShowField command, CommandContext context)
        {
            return(handler.UpdateAsync <SchemaDomainObject>(context, s =>
            {
                GuardSchemaField.CanShow(s.Schema, command);

                s.ShowField(command);
            }));
        }
        protected Task On(HideField command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <SchemaDomainObject>(context, s =>
            {
                GuardSchemaField.CanHide(s.State.SchemaDef, command);

                s.HideField(command);
            }));
        }
Beispiel #4
0
        public void CanDisable_should_throw_exception_if_already_disabled()
        {
            var command = new DisableField {
                FieldId = 1
            };

            schema.FieldsById[1].Disable();

            Assert.Throws <DomainException>(() => GuardSchemaField.CanDisable(schema, command));
        }
Beispiel #5
0
        public void CanHide_should_throw_exception_if_already_hidden()
        {
            var command = new HideField {
                FieldId = 1
            };

            schema.FieldsById[1].Hide();

            Assert.Throws <DomainException>(() => GuardSchemaField.CanHide(schema, command));
        }
Beispiel #6
0
        public void CanUpdate_should_throw_exception_if_locked()
        {
            var command = new UpdateField {
                FieldId = 1, Properties = new StringFieldProperties()
            };

            schema.FieldsById[1].Lock();

            Assert.Throws <DomainException>(() => GuardSchemaField.CanUpdate(schema, command));
        }
Beispiel #7
0
        public void CanDelete_should_throw_exception_if_locked()
        {
            var command = new DeleteField {
                FieldId = 1
            };

            schema.FieldsById[1].Lock();

            Assert.Throws <DomainException>(() => GuardSchemaField.CanDelete(schema, command));
        }
Beispiel #8
0
        public void CanEnable_should_not_throw_exception_if_disabled()
        {
            var command = new EnableField {
                FieldId = 1
            };

            schema.FieldsById[1].Disable();

            GuardSchemaField.CanEnable(schema, command);
        }
Beispiel #9
0
        public void CanShow_should_not_throw_exception_if_hidden()
        {
            var command = new ShowField {
                FieldId = 1
            };

            schema.FieldsById[1].Hide();

            GuardSchemaField.CanShow(schema, command);
        }
        protected Task On(AddField command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <SchemaDomainObject>(context, s =>
            {
                GuardSchemaField.CanAdd(s.Snapshot.SchemaDef, command);

                s.Add(command);

                context.Complete(EntityCreatedResult.Create(s.Snapshot.SchemaDef.FieldsById.Values.First(x => x.Name == command.Name).Id, s.Version));
            }));
        }
Beispiel #11
0
        protected override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case AddField addField:
                return(UpdateReturnAsync(addField, c =>
                {
                    GuardSchemaField.CanAdd(Snapshot.SchemaDef, c);

                    Add(c);

                    var id = 0L;

                    if (c.ParentFieldId == null)
                    {
                        id = Snapshot.SchemaDef.FieldsByName[c.Name].Id;
                    }
                    else
                    {
                        id = ((IArrayField)Snapshot.SchemaDef.FieldsById[c.ParentFieldId.Value]).FieldsByName[c.Name].Id;
                    }

                    return EntityCreatedResult.Create(id, NewVersion);
                }));

            case CreateSchema createSchema:
                return(CreateAsync(createSchema, async c =>
                {
                    await GuardSchema.CanCreate(c, appProvider);

                    Create(c);
                }));

            case DeleteField deleteField:
                return(UpdateAsync(deleteField, c =>
                {
                    GuardSchemaField.CanDelete(Snapshot.SchemaDef, deleteField);

                    DeleteField(c);
                }));

            case LockField lockField:
                return(UpdateAsync(lockField, c =>
                {
                    GuardSchemaField.CanLock(Snapshot.SchemaDef, lockField);

                    LockField(c);
                }));

            case HideField hideField:
                return(UpdateAsync(hideField, c =>
                {
                    GuardSchemaField.CanHide(Snapshot.SchemaDef, c);

                    HideField(c);
                }));

            case ShowField showField:
                return(UpdateAsync(showField, c =>
                {
                    GuardSchemaField.CanShow(Snapshot.SchemaDef, c);

                    ShowField(c);
                }));

            case DisableField disableField:
                return(UpdateAsync(disableField, c =>
                {
                    GuardSchemaField.CanDisable(Snapshot.SchemaDef, c);

                    DisableField(c);
                }));

            case EnableField enableField:
                return(UpdateAsync(enableField, c =>
                {
                    GuardSchemaField.CanEnable(Snapshot.SchemaDef, c);

                    EnableField(c);
                }));

            case UpdateField updateField:
                return(UpdateAsync(updateField, c =>
                {
                    GuardSchemaField.CanUpdate(Snapshot.SchemaDef, c);

                    UpdateField(c);
                }));

            case ReorderFields reorderFields:
                return(UpdateAsync(reorderFields, c =>
                {
                    GuardSchema.CanReorder(Snapshot.SchemaDef, c);

                    Reorder(c);
                }));

            case UpdateSchema updateSchema:
                return(UpdateAsync(updateSchema, c =>
                {
                    GuardSchema.CanUpdate(Snapshot.SchemaDef, c);

                    Update(c);
                }));

            case PublishSchema publishSchema:
                return(UpdateAsync(publishSchema, c =>
                {
                    GuardSchema.CanPublish(Snapshot.SchemaDef, c);

                    Publish(c);
                }));

            case UnpublishSchema unpublishSchema:
                return(UpdateAsync(unpublishSchema, c =>
                {
                    GuardSchema.CanUnpublish(Snapshot.SchemaDef, c);

                    Unpublish(c);
                }));

            case ConfigureScripts configureScripts:
                return(UpdateAsync(configureScripts, c =>
                {
                    GuardSchema.CanConfigureScripts(Snapshot.SchemaDef, c);

                    ConfigureScripts(c);
                }));

            case ChangeCategory changeCategory:
                return(UpdateAsync(changeCategory, c =>
                {
                    GuardSchema.CanChangeCategory(Snapshot.SchemaDef, c);

                    ChangeCategory(c);
                }));

            case DeleteSchema deleteSchema:
                return(UpdateAsync(deleteSchema, c =>
                {
                    GuardSchema.CanDelete(Snapshot.SchemaDef, c);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #12
0
        protected override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case CreateSchema createSchema:
                return(CreateAsync(createSchema, async c =>
                {
                    await GuardSchema.CanCreate(c, appProvider);

                    Create(c);
                }));

            case AddField addField:
                return(UpdateReturnAsync(addField, c =>
                {
                    GuardSchemaField.CanAdd(Snapshot.SchemaDef, c);

                    Add(c);

                    return EntityCreatedResult.Create(Snapshot.SchemaDef.FieldsById.Values.First(x => x.Name == addField.Name).Id, NewVersion);
                }));

            case DeleteField deleteField:
                return(UpdateAsync(deleteField, c =>
                {
                    GuardSchemaField.CanDelete(Snapshot.SchemaDef, deleteField);

                    DeleteField(c);
                }));

            case LockField lockField:
                return(UpdateAsync(lockField, c =>
                {
                    GuardSchemaField.CanLock(Snapshot.SchemaDef, lockField);

                    LockField(c);
                }));

            case HideField hideField:
                return(UpdateAsync(hideField, c =>
                {
                    GuardSchemaField.CanHide(Snapshot.SchemaDef, c);

                    HideField(c);
                }));

            case ShowField showField:
                return(UpdateAsync(showField, c =>
                {
                    GuardSchemaField.CanShow(Snapshot.SchemaDef, c);

                    ShowField(c);
                }));

            case DisableField disableField:
                return(UpdateAsync(disableField, c =>
                {
                    GuardSchemaField.CanDisable(Snapshot.SchemaDef, c);

                    DisableField(c);
                }));

            case EnableField enableField:
                return(UpdateAsync(enableField, c =>
                {
                    GuardSchemaField.CanEnable(Snapshot.SchemaDef, c);

                    EnableField(c);
                }));

            case UpdateField updateField:
                return(UpdateAsync(updateField, c =>
                {
                    GuardSchemaField.CanUpdate(Snapshot.SchemaDef, c);

                    UpdateField(c);
                }));

            case ReorderFields reorderFields:
                return(UpdateAsync(reorderFields, c =>
                {
                    GuardSchema.CanReorder(Snapshot.SchemaDef, c);

                    Reorder(c);
                }));

            case UpdateSchema updateSchema:
                return(UpdateAsync(updateSchema, c =>
                {
                    GuardSchema.CanUpdate(Snapshot.SchemaDef, c);

                    Update(c);
                }));

            case PublishSchema publishSchema:
                return(UpdateAsync(publishSchema, c =>
                {
                    GuardSchema.CanPublish(Snapshot.SchemaDef, c);

                    Publish(c);
                }));

            case UnpublishSchema unpublishSchema:
                return(UpdateAsync(unpublishSchema, c =>
                {
                    GuardSchema.CanUnpublish(Snapshot.SchemaDef, c);

                    Unpublish(c);
                }));

            case ConfigureScripts configureScripts:
                return(UpdateAsync(configureScripts, c =>
                {
                    GuardSchema.CanConfigureScripts(Snapshot.SchemaDef, c);

                    ConfigureScripts(c);
                }));

            case DeleteSchema deleteSchema:
                return(UpdateAsync(deleteSchema, c =>
                {
                    GuardSchema.CanDelete(Snapshot.SchemaDef, c);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
        public override Task <object?> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case AddField addField:
                return(UpdateReturn(addField, c =>
                {
                    GuardSchemaField.CanAdd(c, Snapshot.SchemaDef);

                    Add(c);

                    return Snapshot;
                }));

            case CreateSchema createSchema:
                return(CreateReturn(createSchema, c =>
                {
                    GuardSchema.CanCreate(c);

                    Create(c);

                    return Snapshot;
                }));

            case SynchronizeSchema synchronizeSchema:
                return(UpdateReturn(synchronizeSchema, c =>
                {
                    GuardSchema.CanSynchronize(c);

                    Synchronize(c);

                    return Snapshot;
                }));

            case DeleteField deleteField:
                return(UpdateReturn(deleteField, c =>
                {
                    GuardSchemaField.CanDelete(deleteField, Snapshot.SchemaDef);

                    DeleteField(c);

                    return Snapshot;
                }));

            case LockField lockField:
                return(UpdateReturn(lockField, c =>
                {
                    GuardSchemaField.CanLock(lockField, Snapshot.SchemaDef);

                    LockField(c);

                    return Snapshot;
                }));

            case HideField hideField:
                return(UpdateReturn(hideField, c =>
                {
                    GuardSchemaField.CanHide(c, Snapshot.SchemaDef);

                    HideField(c);

                    return Snapshot;
                }));

            case ShowField showField:
                return(UpdateReturn(showField, c =>
                {
                    GuardSchemaField.CanShow(c, Snapshot.SchemaDef);

                    ShowField(c);

                    return Snapshot;
                }));

            case DisableField disableField:
                return(UpdateReturn(disableField, c =>
                {
                    GuardSchemaField.CanDisable(c, Snapshot.SchemaDef);

                    DisableField(c);

                    return Snapshot;
                }));

            case EnableField enableField:
                return(UpdateReturn(enableField, c =>
                {
                    GuardSchemaField.CanEnable(c, Snapshot.SchemaDef);

                    EnableField(c);

                    return Snapshot;
                }));

            case UpdateField updateField:
                return(UpdateReturn(updateField, c =>
                {
                    GuardSchemaField.CanUpdate(c, Snapshot.SchemaDef);

                    UpdateField(c);

                    return Snapshot;
                }));

            case ReorderFields reorderFields:
                return(UpdateReturn(reorderFields, c =>
                {
                    GuardSchema.CanReorder(c, Snapshot.SchemaDef);

                    Reorder(c);

                    return Snapshot;
                }));

            case UpdateSchema updateSchema:
                return(UpdateReturn(updateSchema, c =>
                {
                    GuardSchema.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case PublishSchema publishSchema:
                return(UpdateReturn(publishSchema, c =>
                {
                    GuardSchema.CanPublish(c);

                    Publish(c);

                    return Snapshot;
                }));

            case UnpublishSchema unpublishSchema:
                return(UpdateReturn(unpublishSchema, c =>
                {
                    GuardSchema.CanUnpublish(c);

                    Unpublish(c);

                    return Snapshot;
                }));

            case ConfigureFieldRules configureFieldRules:
                return(UpdateReturn(configureFieldRules, c =>
                {
                    GuardSchema.CanConfigureFieldRules(c);

                    ConfigureFieldRules(c);

                    return Snapshot;
                }));

            case ConfigureScripts configureScripts:
                return(UpdateReturn(configureScripts, c =>
                {
                    GuardSchema.CanConfigureScripts(c);

                    ConfigureScripts(c);

                    return Snapshot;
                }));

            case ChangeCategory changeCategory:
                return(UpdateReturn(changeCategory, c =>
                {
                    GuardSchema.CanChangeCategory(c);

                    ChangeCategory(c);

                    return Snapshot;
                }));

            case ConfigurePreviewUrls configurePreviewUrls:
                return(UpdateReturn(configurePreviewUrls, c =>
                {
                    GuardSchema.CanConfigurePreviewUrls(c);

                    ConfigurePreviewUrls(c);

                    return Snapshot;
                }));

            case ConfigureUIFields configureUIFields:
                return(UpdateReturn(configureUIFields, c =>
                {
                    GuardSchema.CanConfigureUIFields(c, Snapshot.SchemaDef);

                    ConfigureUIFields(c);

                    return Snapshot;
                }));

            case DeleteSchema deleteSchema:
                return(Update(deleteSchema, c =>
                {
                    GuardSchema.CanDelete(c);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #14
0
        protected override Task <object?> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case AddField addField:
                return(UpdateReturn(addField, c =>
                {
                    GuardSchemaField.CanAdd(c, Snapshot.SchemaDef);

                    Add(c);

                    long id;

                    if (c.ParentFieldId == null)
                    {
                        id = Snapshot.SchemaDef.FieldsByName[c.Name].Id;
                    }
                    else
                    {
                        id = ((IArrayField)Snapshot.SchemaDef.FieldsById[c.ParentFieldId.Value]).FieldsByName[c.Name].Id;
                    }

                    return Snapshot;
                }));

            case CreateSchema createSchema:
                return(CreateReturn(createSchema, c =>
                {
                    GuardSchema.CanCreate(c);

                    Create(c);

                    return Snapshot;
                }));

            case SynchronizeSchema synchronizeSchema:
                return(UpdateReturn(synchronizeSchema, c =>
                {
                    GuardSchema.CanSynchronize(c);

                    Synchronize(c);

                    return Snapshot;
                }));

            case DeleteField deleteField:
                return(UpdateReturn(deleteField, c =>
                {
                    GuardSchemaField.CanDelete(deleteField, Snapshot.SchemaDef);

                    DeleteField(c);

                    return Snapshot;
                }));

            case LockField lockField:
                return(UpdateReturn(lockField, c =>
                {
                    GuardSchemaField.CanLock(lockField, Snapshot.SchemaDef);

                    LockField(c);

                    return Snapshot;
                }));

            case HideField hideField:
                return(UpdateReturn(hideField, c =>
                {
                    GuardSchemaField.CanHide(c, Snapshot.SchemaDef);

                    HideField(c);

                    return Snapshot;
                }));

            case ShowField showField:
                return(UpdateReturn(showField, c =>
                {
                    GuardSchemaField.CanShow(c, Snapshot.SchemaDef);

                    ShowField(c);

                    return Snapshot;
                }));

            case DisableField disableField:
                return(UpdateReturn(disableField, c =>
                {
                    GuardSchemaField.CanDisable(c, Snapshot.SchemaDef);

                    DisableField(c);

                    return Snapshot;
                }));

            case EnableField enableField:
                return(UpdateReturn(enableField, c =>
                {
                    GuardSchemaField.CanEnable(c, Snapshot.SchemaDef);

                    EnableField(c);

                    return Snapshot;
                }));

            case UpdateField updateField:
                return(UpdateReturn(updateField, c =>
                {
                    GuardSchemaField.CanUpdate(c, Snapshot.SchemaDef);

                    UpdateField(c);

                    return Snapshot;
                }));

            case ReorderFields reorderFields:
                return(UpdateReturn(reorderFields, c =>
                {
                    GuardSchema.CanReorder(c, Snapshot.SchemaDef);

                    Reorder(c);

                    return Snapshot;
                }));

            case UpdateSchema updateSchema:
                return(UpdateReturn(updateSchema, c =>
                {
                    GuardSchema.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case PublishSchema publishSchema:
                return(UpdateReturn(publishSchema, c =>
                {
                    GuardSchema.CanPublish(c);

                    Publish(c);

                    return Snapshot;
                }));

            case UnpublishSchema unpublishSchema:
                return(UpdateReturn(unpublishSchema, c =>
                {
                    GuardSchema.CanUnpublish(c);

                    Unpublish(c);

                    return Snapshot;
                }));

            case ConfigureScripts configureScripts:
                return(UpdateReturn(configureScripts, c =>
                {
                    GuardSchema.CanConfigureScripts(c);

                    ConfigureScripts(c);

                    return Snapshot;
                }));

            case ChangeCategory changeCategory:
                return(UpdateReturn(changeCategory, c =>
                {
                    GuardSchema.CanChangeCategory(c);

                    ChangeCategory(c);

                    return Snapshot;
                }));

            case ConfigurePreviewUrls configurePreviewUrls:
                return(UpdateReturn(configurePreviewUrls, c =>
                {
                    GuardSchema.CanConfigurePreviewUrls(c);

                    ConfigurePreviewUrls(c);

                    return Snapshot;
                }));

            case ConfigureUIFields configureUIFields:
                return(UpdateReturn(configureUIFields, c =>
                {
                    GuardSchema.CanConfigureUIFields(c, Snapshot.SchemaDef);

                    ConfigureUIFields(c);

                    return Snapshot;
                }));

            case DeleteSchema deleteSchema:
                return(Update(deleteSchema, c =>
                {
                    GuardSchema.CanDelete(c);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }