Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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 MoveCore(MoveAsset move)
        {
            await GuardAsset.CanMove(move, Snapshot, assetQuery);

            Move(move);
        }
        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();
            }
        }