Esempio n. 1
0
        public virtual async Task <Tag> UpdateAsync(Guid id, [NotNull] string name,
                                                    CancellationToken cancellationToken = default)
        {
            var entity = await TagRepository.GetAsync(id, cancellationToken : cancellationToken);

            if (name != entity.Name &&
                await TagRepository.AnyAsync(entity.EntityType, name, entity.TenantId, cancellationToken))
            {
                throw new TagAlreadyExistException(entity.EntityType, name);
            }

            entity.SetName(name);

            return(await TagRepository.UpdateAsync(entity, cancellationToken : cancellationToken));
        }
Esempio n. 2
0
    public virtual async Task <Tag> UpdateAsync(Guid id, [NotNull] string name)
    {
        Check.NotNullOrEmpty(name, nameof(name));

        var tag = await TagRepository.GetAsync(id);

        if (name != tag.Name &&
            await TagRepository.AnyAsync(tag.EntityType, name))
        {
            throw new TagAlreadyExistException(tag.EntityType, name);
        }

        tag.SetName(name);

        return(tag);
    }
Esempio n. 3
0
        public virtual async Task <Tag> InsertAsync(Guid id, [NotNull] string entityType, [NotNull] string name,
                                                    Guid?tenantId = null, CancellationToken cancellationToken = default)
        {
            if (!await TagDefinitionStore.IsDefinedAsync(entityType))
            {
                throw new EntityNotTaggableException(entityType);
            }

            if (await TagRepository.AnyAsync(entityType, name, tenantId, cancellationToken))
            {
                throw new TagAlreadyExistException(entityType, name);
            }

            return(await TagRepository.InsertAsync(new Tag(id, entityType, name, tenantId),
                                                   cancellationToken : cancellationToken));
        }
Esempio n. 4
0
    public virtual async Task <Tag> CreateAsync(Guid id,
                                                [NotNull] string entityType,
                                                [NotNull] string name)
    {
        if (!await TagDefinitionStore.IsDefinedAsync(entityType))
        {
            throw new EntityNotTaggableException(entityType);
        }

        if (await TagRepository.AnyAsync(entityType, name))
        {
            throw new TagAlreadyExistException(entityType, name);
        }

        return
            (new Tag(id, entityType, name, CurrentTenant.Id));
    }