예제 #1
0
파일: AssetGrain.cs 프로젝트: zxbe/squidex
        protected override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case CreateAsset createRule:
                return(CreateReturnAsync(createRule, async c =>
                {
                    GuardAsset.CanCreate(c);

                    c.Tags = await tagService.NormalizeTagsAsync(c.AppId.Id, TagGroups.Assets, c.Tags, Snapshot.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 TagAsset tagAsset:
                return(UpdateAsync(tagAsset, async c =>
                {
                    GuardAsset.CanTag(c);

                    c.Tags = await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, c.Tags, Snapshot.Tags);

                    Tag(c);
                }));

            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 RenameAsset renameAsset:
                return(UpdateAsync(renameAsset, c =>
                {
                    GuardAsset.CanRename(c, Snapshot.FileName);

                    Rename(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }