Exemplo n.º 1
0
        protected Task On(CreateSchema command, CommandContext context)
        {
            return(handler.CreateSyncedAsync <SchemaDomainObject>(context, async s =>
            {
                await GuardSchema.CanCreate(command, appProvider);

                s.Create(command);

                context.Complete(EntityCreatedResult.Create(command.SchemaId, s.Version));
            }));
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
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();
            }
        }