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)); }
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()); }
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(); }
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()); }
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)); }
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); })); }
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)); }
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); }
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(); }
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(); }
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." }); }
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")); } } }
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); } }
public void Delete(DeleteContent command) { RaiseEvent(SimpleMapper.Map(command, new ContentDeleted())); }
protected Task On(DeleteContent command, CommandContext context) { return(handler.UpdateAsync <ContentDomainObject>(context, c => c.Delete(command))); }
public void CanDelete_should_not_throw_exception() { var command = new DeleteContent(); GuardContent.CanDelete(schema, command); }
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(); } }
private void Delete(DeleteContent command) { Raise(command, new ContentDeleted()); }
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(); } }
public static void CanDelete(DeleteContent command) { Guard.NotNull(command, nameof(command)); }