private AssetCommand CreateCommandCore(BulkTask task) { var job = task.CommandJob; switch (job.Type) { case BulkUpdateAssetType.Annotate: { var command = new AnnotateAsset(); EnrichAndCheckPermission(task, command, Permissions.AppAssetsUpdate); return(command); } case BulkUpdateAssetType.Move: { var command = new MoveAsset(); EnrichAndCheckPermission(task, command, Permissions.AppAssetsUpdate); return(command); } case BulkUpdateAssetType.Delete: { var command = new DeleteAsset(); EnrichAndCheckPermission(task, command, Permissions.AppAssetsDelete); return(command); } default: throw new NotSupportedException(); } }
public void CanDelete_should_not_throw_exception() { var command = new DeleteAsset { AppId = appId }; GuardAsset.CanDelete(command); }
private async Task DeleteCore(DeleteAsset delete) { await GuardAsset.CanDelete(delete, Snapshot, contentRepository); await NormalizeTagsAsync(Snapshot.AppId.Id, null); Delete(delete); }
public void Delete(DeleteAsset command) { VerifyNotDeleted(); RaiseEvent(SimpleMapper.Map(command, new AssetDeleted { DeletedSize = Snapshot.TotalSize })); }
public async Task CanDelete_should_not_throw_exception() { var command = new DeleteAsset { AppId = appId }; await GuardAsset.CanDelete(command, Asset(), contentRepository); }
protected Task On(DeleteAsset command, CommandContext context) { return(handler.UpdateSyncedAsync <AssetDomainObject>(context, a => { GuardAsset.CanDelete(command); a.Delete(command); })); }
/// <summary> /// Delete asset by AssetId /// </summary> /// <param name="AssetId"></param> public void DeleteAsset(int AssetId) { var proc = new DeleteAsset(this.database) { AssetId = AssetId }; proc.Execute(); }
public object Delete(DeleteAsset request) { var entity = request.ConvertTo <Asset>(); return(InTransaction(db => { Logic.Remove(entity); return new CommonResponse(); })); }
public AssetDomainObject Delete(DeleteAsset command) { VerifyCreatedAndNotDeleted(); RaiseEvent(SimpleMapper.Map(command, new AssetDeleted { DeletedSize = Snapshot.TotalSize })); return(this); }
public async Task Delete_should_not_throw_exception_if_referenced_by_other_item_but_forced() { var command = new DeleteAsset(); await ExecuteCreateAsync(); A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id)) .Returns(true); await PublishAsync(command); }
public AssetDomainObject Delete(DeleteAsset command) { Guard.NotNull(command, nameof(command)); VerifyCreatedAndNotDeleted(); RaiseEvent(SimpleMapper.Map(command, new AssetDeleted { DeletedSize = totalSize })); return(this); }
public async Task CanDelete_should_throw_exception_if_referenced() { var asset = Asset(); var command = new DeleteAsset { AppId = appId, CheckReferrers = true }; A.CallTo(() => contentRepository.HasReferrersAsync(appId.Id, asset.Id, SearchScope.All)) .Returns(true); await Assert.ThrowsAsync <DomainException>(() => GuardAsset.CanDelete(command, asset, contentRepository)); }
public async Task Delete_should_throw_exception_if_referenced_by_other_item() { var command = new DeleteAsset { CheckReferrers = true }; await ExecuteCreateAsync(); A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id)) .Returns(true); await Assert.ThrowsAsync <DomainException>(() => PublishAsync(command)); }
public static async Task CanDelete(DeleteAsset command, IAssetEntity asset, IContentRepository contentRepository) { Guard.NotNull(command, nameof(command)); if (command.CheckReferrers) { var hasReferrer = await contentRepository.HasReferrersAsync(asset.AppId.Id, asset.Id, SearchScope.All); if (hasReferrer) { throw new DomainException(T.Get("assets.referenced")); } } }
private async Task DeleteCore(DeleteAsset delete, AssetOperation operation) { if (delete.CheckReferrers) { await operation.CheckReferrersAsync(); } if (!delete.DoNotScript) { await operation.ExecuteDeleteScriptAsync(delete); } await operation.UnsetTags(); Delete(delete); }
public async Task Delete_should_create_events_with_total_file_size() { var command = new DeleteAsset(); await ExecuteCreateAsync(); await ExecuteUpdateAsync(); var result = await sut.ExecuteAsync(CreateAssetCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(2)); Assert.True(sut.Snapshot.IsDeleted); LastEvents .ShouldHaveSameEvents( CreateAssetEvent(new AssetDeleted { DeletedSize = 2048 }) ); }
public static Task ExecuteDeleteScriptAsync(this AssetOperation operation, DeleteAsset delete) { var script = operation.App.AssetScripts?.Delete; if (string.IsNullOrWhiteSpace(script)) { return(Task.CompletedTask); } // Script vars are just wrappers over dictionaries for better performance. var vars = new AssetScriptVars { Command = new AssetCommandScriptVars { Permanent = delete.Permanent }, Operation = "Delete" }; return(ExecuteScriptAsync(operation, script, vars)); }
public static Task ExecuteDeleteScriptAsync(this AssetOperation operation, DeleteAsset delete) { var script = operation.App.AssetScripts?.Delete; if (string.IsNullOrWhiteSpace(script)) { return(Task.CompletedTask); } var vars = new ScriptVars { // Use a dictionary for better performance, because no reflection is involved. [ScriptKeys.Command] = new Dictionary <string, object?> { [ScriptKeys.Permanent] = delete.Permanent }, [ScriptKeys.Operation] = "Delete" }; return(ExecuteScriptAsync(operation, script, vars)); }
protected Task On(DeleteAsset command, CommandContext context) { return(handler.UpdateAsync <AssetDomainObject>(context, c => c.Delete(command))); }
public static void CanDelete(DeleteAsset command) { Guard.NotNull(command, nameof(command)); }
private void Delete(DeleteAsset command) { Raise(command, new AssetDeleted { DeletedSize = Snapshot.TotalSize }); }