示例#1
0
        public async Task <IActionResult> DeleteContent(string name, Guid id)
        {
            await contentQuery.FindSchemaAsync(App, name);

            var command = new DeleteContent {
                ContentId = id
            };

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
        public IContentBuilder <T> Delete()
        {
            foreach (var latest in Fixture.Latest)
            {
                var command = new DeleteContent(latest, false);
                var content = command.Execute();

                Add(content);
            }

            return(new ContentBuilder <T>(Fixture, _contents));
        }
示例#3
0
        public async Task <IActionResult> DeleteContent(string app, string name, Guid id)
        {
            await contentQuery.ThrowIfSchemaNotExistsAsync(Context().WithSchemaName(name));

            var command = new DeleteContent {
                ContentId = id
            };

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
示例#4
0
        public async Task <IActionResult> DeleteContent(string app, string name, Guid id)
        {
            await contentQuery.GetSchemaOrThrowAsync(Context, name);

            var command = new DeleteContent {
                ContentId = id
            };

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
        public void ForceDelete()
        {
            foreach (var latest in Fixture.Latest)
            {
                var command = new DeleteContent(latest, false);
                command.Execute();

                Fixture.Contents.Remove(latest);
            }

            Fixture.Latest.Clear();
        }
示例#6
0
        public async Task <IActionResult> DeleteContent(string app, string name, DomainId id,
                                                        [FromQuery] bool checkReferrers = false,
                                                        [FromQuery] bool permanent      = false)
        {
            var command = new DeleteContent {
                ContentId = id, CheckReferrers = checkReferrers, Permanent = permanent
            };

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
示例#7
0
        public async Task CanDelete_should_throw_exception_if_referenced()
        {
            var schema = CreateSchema(true);

            var content = CreateContent(Status.Published);
            var command = new DeleteContent();

            A.CallTo(() => contentRepository.HasReferrersAsync(appId.Id, content.Id, SearchScope.All))
            .Returns(true);

            await Assert.ThrowsAsync <DomainException>(() => GuardContent.CanDelete(command, content, contentRepository, schema));
        }
示例#8
0
        protected Task On(DeleteContent command, CommandContext context)
        {
            return(handler.UpdateAsync <ContentDomainObject>(context, async content =>
            {
                GuardContent.CanDelete(command);

                var operationContext = await CreateContext(command, content, () => "Failed to delete content.");

                await operationContext.ExecuteScriptAsync(x => x.ScriptDelete, "Delete");

                content.Delete(command);
            }));
        }
示例#9
0
        public async Task Delete_should_throw_exception_if_referenced_by_other_item()
        {
            await ExecuteCreateAsync();

            var command = new DeleteContent {
                CheckReferrers = true
            };

            A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All))
            .Returns(true);

            await Assert.ThrowsAsync <DomainException>(() => PublishAsync(command));
        }
示例#10
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);
        }
示例#11
0
        public async Task Delete_should_create_events_and_update_deleted_flag()
        {
            await ExecuteCreateAsync();

            var command = new DeleteContent();

            var result = await PublishAsync(command);

            result.ShouldBeEquivalent(new EntitySavedResult(1));

            Assert.True(sut.Snapshot.IsDeleted);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentDeleted())
                );

            A.CallTo(() => scriptEngine.ExecuteAsync(ScriptContext(data, null, Status.Draft), "<delete-script>", ScriptOptions()))
            .MustHaveHappened();
        }
示例#12
0
        public async Task Delete_should_update_properties_and_create_events()
        {
            var command = new DeleteContent();

            await ExecuteCreateAsync();

            var result = await sut.ExecuteAsync(CreateContentCommand(command));

            result.ShouldBeEquivalent(new EntitySavedResult(1));

            Assert.True(sut.Snapshot.IsDeleted);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentDeleted())
                );

            A.CallTo(() => scriptEngine.Execute(A <ScriptContext> .Ignored, "<delete-script>"))
            .MustHaveHappened();
        }
示例#13
0
        private void AddContentDelete(string schemaType, string schemaName)
        {
            AddField(new FieldType
            {
                Name         = $"delete{schemaType}Content",
                Arguments    = CreateIdArguments(schemaName),
                ResolvedType = AllTypes.CommandVersion,
                Resolver     = ResolveAsync((c, publish) =>
                {
                    var contentId = c.GetArgument <Guid>("id");

                    var command = new DeleteContent {
                        ContentId = contentId
                    };

                    return(publish(command));
                }),
                Description = $"Delete an {schemaName} content."
            });
        }
示例#14
0
        public static async Task CanDelete(DeleteContent command,
                                           IContentEntity content,
                                           IContentRepository contentRepository,
                                           ISchemaEntity schema)
        {
            Guard.NotNull(command, nameof(command));

            if (schema.SchemaDef.IsSingleton)
            {
                throw new DomainException(T.Get("contents.singletonNotDeletable"));
            }

            if (command.CheckReferrers)
            {
                var hasReferrer = await contentRepository.HasReferrersAsync(content.AppId.Id, command.ContentId, SearchScope.All);

                if (hasReferrer)
                {
                    throw new DomainException(T.Get("contents.referenced"));
                }
            }
        }
示例#15
0
        private void DeleteLocalContent(DeleteContent content)
        {
            XmlData entryToDelete = null;

            foreach (var child in ProjectMetaDataFile.Root.Children)
            {
                if (child.GetAttributeValue("Name").Compare(content.ContentName))
                {
                    entryToDelete = child;
                }
            }
            if (entryToDelete == null)
            {
                return;
            }
            DeleteFiles(entryToDelete);
            ProjectMetaDataFile.Root.RemoveChild(entryToDelete);
            UpdateLastTimeUpdatedFile();
            SaveXmlFile();
            if (ContentDeleted != null)
            {
                ContentDeleted(content.ContentName);
            }
        }
示例#16
0
 public void Delete(DeleteContent command)
 {
     RaiseEvent(SimpleMapper.Map(command, new ContentDeleted()));
 }
示例#17
0
 protected Task On(DeleteContent command, CommandContext context)
 {
     return(handler.UpdateAsync <ContentDomainObject>(context, c => c.Delete(command)));
 }
示例#18
0
        public void CanDelete_should_not_throw_exception()
        {
            var command = new DeleteContent();

            GuardContent.CanDelete(schema, command);
        }
示例#19
0
        private async Task <ICommand> CreateCommandAsync(DomainId id, BulkTask task)
        {
            var job = task.Job;

            switch (job.Type)
            {
            case BulkUpdateType.Create:
            {
                var command = new CreateContent {
                    Data = job.Data !
                };

                await EnrichAsync(id, task, command, Permissions.AppContentsCreate);

                return(command);
            }

            case BulkUpdateType.Update:
            {
                var command = new UpdateContent {
                    Data = job.Data !
                };

                await EnrichAsync(id, task, command, Permissions.AppContentsUpdateOwn);

                return(command);
            }

            case BulkUpdateType.Upsert:
            {
                var command = new UpsertContent {
                    Data = job.Data !
                };

                await EnrichAsync(id, task, command, Permissions.AppContentsUpsert);

                return(command);
            }

            case BulkUpdateType.Patch:
            {
                var command = new PatchContent {
                    Data = job.Data !
                };

                await EnrichAsync(id, task, command, Permissions.AppContentsUpdateOwn);

                return(command);
            }

            case BulkUpdateType.Validate:
            {
                var command = new ValidateContent();

                await EnrichAsync(id, task, command, Permissions.AppContentsReadOwn);

                return(command);
            }

            case BulkUpdateType.ChangeStatus:
            {
                var command = new ChangeContentStatus {
                    Status = job.Status, DueTime = job.DueTime
                };

                await EnrichAsync(id, task, command, Permissions.AppContentsUpdateOwn);

                return(command);
            }

            case BulkUpdateType.Delete:
            {
                var command = new DeleteContent();

                await EnrichAsync(id, task, command, Permissions.AppContentsDeleteOwn);

                return(command);
            }

            default:
                throw new NotSupportedException();
            }
        }
示例#20
0
 private void Delete(DeleteContent command)
 {
     Raise(command, new ContentDeleted());
 }
示例#21
0
        private async Task <ContentCommand> CreateCommandAsync(BulkTask task)
        {
            var job = task.CommandJob;

            switch (job.Type)
            {
            case BulkUpdateContentType.Create:
            {
                var command = new CreateContent();

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsCreate);

                return(command);
            }

            case BulkUpdateContentType.Update:
            {
                var command = new UpdateContent();

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsUpdateOwn);

                return(command);
            }

            case BulkUpdateContentType.Upsert:
            {
                var command = new UpsertContent();

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsUpsert);

                return(command);
            }

            case BulkUpdateContentType.Patch:
            {
                var command = new PatchContent();

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsUpdateOwn);

                return(command);
            }

            case BulkUpdateContentType.Validate:
            {
                var command = new ValidateContent();

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsReadOwn);

                return(command);
            }

            case BulkUpdateContentType.ChangeStatus:
            {
                var command = new ChangeContentStatus {
                    Status = job.Status ?? Status.Draft
                };

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsChangeStatusOwn);

                return(command);
            }

            case BulkUpdateContentType.Delete:
            {
                var command = new DeleteContent();

                await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsDeleteOwn);

                return(command);
            }

            default:
                throw new NotSupportedException();
            }
        }
示例#22
0
 public static void CanDelete(DeleteContent command)
 {
     Guard.NotNull(command, nameof(command));
 }