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(); } }
private async Task <HashSet <string> > NormalizeTagsAsync(DomainId appId, HashSet <string>?tags) { var normalized = await assetTags.NormalizeTagsAsync(appId, TagGroups.Assets, tags, Snapshot.Tags); return(new HashSet <string>(normalized.Values)); }
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(); } }