Beispiel #1
0
        private async Task DeleteCore(DeleteContent c, ContentOperation operation)
        {
            operation.MustHavePermission(Permissions.AppContentsDelete);
            operation.MustNotDeleteSingleton();

            if (!c.DoNotScript)
            {
                await operation.ExecuteDeleteScriptAsync(c.Permanent);
            }

            if (c.CheckReferrers)
            {
                await operation.CheckReferrersAsync();
            }

            Delete(c);
        }
Beispiel #2
0
        public override Task <CommandResult> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case UpsertContent upsertContent:
                return(UpsertReturnAsync(upsertContent, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    if (Version > EtagVersion.Empty && !IsDeleted(Snapshot))
                    {
                        await UpdateCore(c.AsUpdate(), operation);
                    }
                    else
                    {
                        await CreateCore(c.AsCreate(), operation);
                    }

                    if (Is.OptionalChange(operation.Snapshot.EditingStatus(), c.Status))
                    {
                        await ChangeCore(c.AsChange(c.Status.Value), operation);
                    }

                    return Snapshot;
                }));

            case CreateContent createContent:
                return(CreateReturnAsync(createContent, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await CreateCore(c, operation);

                    if (operation.Schema.SchemaDef.Type == SchemaType.Singleton)
                    {
                        ChangeStatus(c.AsChange(Status.Published));
                    }
                    else if (Is.OptionalChange(Snapshot.Status, c.Status))
                    {
                        await ChangeCore(c.AsChange(c.Status.Value), operation);
                    }

                    return Snapshot;
                }));

            case ValidateContent validate:
                return(UpdateReturnAsync(validate, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await ValidateCore(operation);

                    return true;
                }));

            case CreateContentDraft createDraft:
                return(UpdateReturnAsync(createDraft, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await CreateDraftCore(c, operation);

                    return Snapshot;
                }));

            case DeleteContentDraft deleteDraft:
                return(UpdateReturnAsync(deleteDraft, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    DeleteDraftCore(c, operation);

                    return Snapshot;
                }));

            case PatchContent patchContent:
                return(UpdateReturnAsync(patchContent, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await PatchCore(c, operation);

                    return Snapshot;
                }));

            case UpdateContent updateContent:
                return(UpdateReturnAsync(updateContent, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await UpdateCore(c, operation);

                    return Snapshot;
                }));

            case CancelContentSchedule cancelContentSchedule:
                return(UpdateReturnAsync(cancelContentSchedule, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    CancelChangeCore(c, operation);

                    return Snapshot;
                }));

            case ChangeContentStatus changeContentStatus:
                return(UpdateReturnAsync(changeContentStatus, async c =>
                {
                    try
                    {
                        if (c.DueTime > SystemClock.Instance.GetCurrentInstant())
                        {
                            ChangeStatusScheduled(c, c.DueTime.Value);
                        }
                        else
                        {
                            var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                            await ChangeCore(c, operation);
                        }
                    }
                    catch (Exception)
                    {
                        if (Snapshot.ScheduleJob != null && Snapshot.ScheduleJob.Id == c.StatusJobId)
                        {
                            CancelChangeStatus(c);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    return Snapshot;
                }));

            case DeleteContent deleteContent when deleteContent.Permanent:
                return(DeletePermanentAsync(deleteContent, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await DeleteCore(c, operation);
                }));

            case DeleteContent deleteContent:
                return(UpdateAsync(deleteContent, async c =>
                {
                    var operation = await ContentOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await DeleteCore(c, operation);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #3
0
        private async Task ValidateCore(ContentOperation operation)
        {
            operation.MustHavePermission(Permissions.AppContentsRead);

            await operation.ValidateContentAndInputAsync(Snapshot.Data, false, Snapshot.IsPublished());
        }