Beispiel #1
0
        public async Task <Tag> InsertAsync(
            Guid id,
            [NotNull] string entityType,
            [NotNull] string name,
            Guid?tenantId = null,
            CancellationToken cancellationToken = default)
        {
            if (await _tagRepository.AnyAsync(entityType, name, tenantId, cancellationToken))
            {
                throw new TagAlreadyExistException(entityType, name);
            }

            if (!await _tagDefinitionStore.IsDefinedAsync(entityType))
            {
                throw new EntityNotTaggableException(entityType);
            }

            return(await _tagRepository.InsertAsync(
                       new Tag(
                           id,
                           entityType,
                           name,
                           tenantId),
                       cancellationToken : cancellationToken));
        }
        /// <summary>
        /// 新增标签
        /// </summary>
        /// <param name="entity">实体信息</param>
        /// <returns></returns>
        public override async Task <bool> InsertAsync(TagInfo entity)
        {
            var any = await _tagRepository.AnyAsync(it => it.TagName == entity.TagName);

            if (any)
            {
                throw new ServiceException("tag already exist.", "200")
                      {
                          HttpStatusCode = HttpStatusCode.BadRequest
                      };
            }
            return(await base.InsertAsync(entity));
        }
Beispiel #3
0
        public async Task ShouldAddWhenGettingAsync()
        {
            var newTagEntityType = _cmsKitTestData.EntityType1;
            var newTagName       = "test_tag_2123";

            var doesExist = await _tagRepository.AnyAsync(newTagEntityType, newTagName);

            doesExist.ShouldBeFalse();

            var newTag = await _tagManager.GetOrAddAsync(newTagEntityType, newTagName);

            newTag.ShouldNotBeNull();

            var doesExistAgain = await _tagRepository.AnyAsync(newTagEntityType, newTagName);

            doesExistAgain.ShouldBeTrue();
        }
Beispiel #4
0
    public async Task ShouldExistAsync(string entityType, string name)
    {
        var tag = await _tagRepository.AnyAsync(entityType, name);

        tag.ShouldBeTrue();
    }