protected override Task <object> ExecuteAsync(IAggregateCommand command) { VerifyNotDeleted(); switch (command) { case CreateAsset createRule: return(CreateReturnAsync(createRule, async c => { GuardAsset.CanCreate(c); c.Tags = await NormalizeTagsAsync(c.AppId.Id, c.Tags); Create(c); return new AssetSavedResult(Version, Snapshot.FileVersion); })); case UpdateAsset updateRule: return(UpdateAsync(updateRule, c => { GuardAsset.CanUpdate(c); Update(c); return new AssetSavedResult(Version, Snapshot.FileVersion); })); case DeleteAsset deleteAsset: return(UpdateAsync(deleteAsset, async c => { GuardAsset.CanDelete(c); await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags); Delete(c); })); case AnnotateAsset annotateAsset: return(UpdateAsync(annotateAsset, async c => { GuardAsset.CanAnnotate(c, Snapshot.FileName, Snapshot.Slug); if (c.Tags != null) { c.Tags = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags); } Annotate(c); })); default: throw new NotSupportedException(); } }
protected override Task <object?> ExecuteAsync(IAggregateCommand command) { VerifyNotDeleted(); switch (command) { case CreateAsset createAsset: return(CreateReturnAsync(createAsset, async c => { await GuardAsset.CanCreate(c, assetQuery); var tagIds = await NormalizeTagsAsync(c.AppId.Id, c.Tags); Create(c, tagIds); return Snapshot; })); case UpdateAsset updateAsset: return(UpdateReturn(updateAsset, c => { GuardAsset.CanUpdate(c); Update(c); return Snapshot; })); case AnnotateAsset annotateAsset: return(UpdateReturnAsync(annotateAsset, async c => { GuardAsset.CanAnnotate(c); var tagIds = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags); Annotate(c, tagIds); return Snapshot; })); case MoveAsset moveAsset: return(UpdateReturnAsync(moveAsset, async c => { await GuardAsset.CanMove(c, assetQuery, Snapshot.ParentId); Move(c); return Snapshot; })); case DeleteAsset deleteAsset: return(UpdateAsync(deleteAsset, async c => { GuardAsset.CanDelete(c); await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags); Delete(c); })); default: throw new NotSupportedException(); } }
public override Task <CommandResult> ExecuteAsync(IAggregateCommand command) { switch (command) { case UpsertAsset upsert: return(UpsertReturnAsync(upsert, async c => { if (Version > EtagVersion.Empty && !IsDeleted()) { UpdateCore(c.AsUpdate()); } else { await CreateCore(c.AsCreate()); } if (Is.OptionalChange(Snapshot.ParentId, c.ParentId)) { await MoveCore(c.AsMove(c.ParentId.Value)); } return Snapshot; })); case CreateAsset c: return(CreateReturnAsync(c, async create => { await CreateCore(create); if (Is.Change(Snapshot.ParentId, c.ParentId)) { await MoveCore(c.AsMove()); } return Snapshot; })); case AnnotateAsset c: return(UpdateReturnAsync(c, async c => { GuardAsset.CanAnnotate(c); if (c.Tags != null) { c.Tags = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags); } Annotate(c); return Snapshot; })); case UpdateAsset update: return(UpdateReturn(update, update => { Update(update); return Snapshot; })); case MoveAsset move: return(UpdateReturnAsync(move, async c => { await MoveCore(c); return Snapshot; })); case DeleteAsset delete when(delete.Permanent): return(DeletePermanentAsync(delete, async c => { await DeleteCore(c); })); case DeleteAsset delete: return(UpdateAsync(delete, async c => { await DeleteCore(c); })); default: throw new NotSupportedException(); } }
public override Task <object?> ExecuteAsync(IAggregateCommand command) { switch (command) { case CreateAsset createAsset: return(CreateReturnAsync(createAsset, async c => { await GuardAsset.CanCreate(c, assetQuery); var tagIds = await NormalizeTagsAsync(c.AppId.Id, c.Tags); Create(c, tagIds); return Snapshot; })); case UpdateAsset updateAsset: return(UpdateReturn(updateAsset, c => { GuardAsset.CanUpdate(c); Update(c); return Snapshot; })); case AnnotateAsset annotateAsset: return(UpdateReturnAsync(annotateAsset, async c => { GuardAsset.CanAnnotate(c); var tagIds = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags); Annotate(c, tagIds); return Snapshot; })); case MoveAsset moveAsset: return(UpdateReturnAsync(moveAsset, async c => { await GuardAsset.CanMove(c, assetQuery, Snapshot.ParentId); Move(c); return Snapshot; })); case DeleteAsset deleteAsset: return(UpdateAsync(deleteAsset, async c => { GuardAsset.CanDelete(c); if (c.CheckReferrers) { var hasReferrer = await contentRepository.HasReferrersAsync(Snapshot.AppId.Id, c.AssetId); if (hasReferrer) { throw new DomainException(T.Get("assets.referenced")); } } await assetTags.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags); Delete(c); })); default: throw new NotSupportedException(); } }
public override Task <object?> ExecuteAsync(IAggregateCommand command) { switch (command) { case CreateAsset createAsset: return(CreateReturnAsync(createAsset, async c => { await GuardAsset.CanCreate(c, assetQuery); if (c.Tags != null) { c.Tags = await NormalizeTagsAsync(c.AppId.Id, c.Tags); } Create(c); return Snapshot; })); case AnnotateAsset annotateAsset: return(UpdateReturnAsync(annotateAsset, async c => { GuardAsset.CanAnnotate(c); if (c.Tags != null) { c.Tags = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags); } Annotate(c); return Snapshot; })); case UpdateAsset updateAsset: return(UpdateReturn(updateAsset, c => { GuardAsset.CanUpdate(c); Update(c); return Snapshot; })); case MoveAsset moveAsset: return(UpdateReturnAsync(moveAsset, async c => { await GuardAsset.CanMove(c, Snapshot, assetQuery); Move(c); return Snapshot; })); case DeleteAsset deleteAsset: return(UpdateAsync(deleteAsset, async c => { await GuardAsset.CanDelete(c, Snapshot, contentRepository); await assetTags.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags); Delete(c); })); default: throw new NotSupportedException(); } }