示例#1
0
        public static (Tag, Event <TagCreated>) On(CreateTag request, Guid userId)
        {
            var tag = new Tag
            {
                Id            = Guid.NewGuid(),
                Key           = request.Key,
                Title         = request.Title,
                CorrelationId = request.CorrelationId,
                Created       = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                Updated       = 0,
                Deleted       = 0
            };

            return(tag, new Event <TagCreated>
            {
                Type = "tag-created",
                Version = 1,
                CorrelationId = request.CorrelationId,
                UserId = userId,
                OccurredOn = tag.Created,
                Payload = new TagCreated
                {
                    TagId = tag.Id
                }
            });
示例#2
0
 public IActionResult Post(CreateTag createTag)
 {
     try {
         return(Ok(TagServiceManagement.CreateTag(createTag)));
     } catch (DuplicateNameException e) {
         return(BadRequest());
     }
 }
示例#3
0
        static InfusioOp <Tag> CreateNewTag(Tag tag)
        {
            var input = new CreateTag(name: tag.Name, description: tag.Description);

            return(CreateTag(
                       Optional(tag.Category)
                       .Map(cat => input.Copy(category: new CategoryReference(cat.Id)))
                       .IfNone(input)
                       ));
        }
示例#4
0
        public async Task <ActionResult <Guid> > Post([FromRoute] string name, [FromRoute] Guid questionId)
        {
            var command = new CreateTag()
            {
                QuestionId = questionId,
                User       = "******",
                TagName    = name
            };
            var result = await _commandDispatcher.DispatchAsync(command).ConfigureAwait(false);

            return(Ok(result));
        }
示例#5
0
        public TagDto CreateTag(CreateTag createTag)
        {
            ValidateTag(createTag.Name);
            Tag tag = new Tag();

            tag.Name = createTag.Name;
            BlogDBContext.Tags.Add(tag);
            BlogDBContext.SaveChanges();

            TagDto tagDto = new TagDto();

            tagDto.Name = tag.Name;
            return(tagDto);
        }
示例#6
0
        /// <summary>
        ///     Create a new tag or get it if it already exists.
        /// </summary>
        /// <param name="createTag">The mutation model.</param>
        /// <returns></returns>
        public async Task <int> CreateTag(CreateTag createTag)
        {
            var request = new GraphQLRequest
            {
                Query     = @"mutation request($boardId:Int $name:String) { create_or_get_tag  (board_id: $boardId, tag_name: $name) {id}}",
                Variables = new
                {
                    boardId = createTag.BoardId,
                    name    = createTag.Name
                }
            };

            var result = await _graphQlHttpClient.SendMutationAsync <CreateTagResponse>(request);

            ThrowResponseErrors(result.Errors);

            return(result.Data.Tag.Id);
        }
示例#7
0
        public async Task <(Result, Tag)> CreateAsync(CreateTag request, Guid userId)
        {
            _logger.LogInformation($"Trying to create tag {request.Key}");

            if (await _tags.CountDocumentsAsync(
                    x => x.CorrelationId == request.CorrelationId ||
                    x.Key == request.Key) > 0)
            {
                return(Result.Conflict, null);
            }

            var(category, categoryCreated) = Tag.On(request, userId);

            await _tags.InsertOneAsync(category);

            await _eventService.PublishAsync(categoryCreated);

            _logger.LogInformation($"Tag {request.Key} created");

            return(Result.Successful, category);
        }
示例#8
0
        /// <summary>
        /// 调用微信接口创建标签
        /// </summary>
        /// <param name="tagName"></param>
        /// <param name="rm"></param>
        /// <returns></returns>
        public ReturnMsg CreateWxTag(string tagName, ReturnMsg rm)
        {
            var paInfo = _wxHelper.GetPaInfo(1, c => c.PA_ID_NO == AbpSession.ORG_NO, AbpSession.BG_NO);

            if (paInfo == null)
            {
                rm.IsSuccess = false;
                rm.msg       = "公众号信息不存在";
                return(rm);
            }
            var requestToken = _wxHelper.GetAccessToken(paInfo, AbpSession.BG_NO);

            if (!requestToken.IsSuccess)
            {
                return(rm);
            }
            var url     = string.Format("https://api.weixin.qq.com/cgi-bin/tags/create?access_token={0}", requestToken.result);
            var tagMoel = new CreateTag {
                name = tagName
            };
            var dic = new Dictionary <string, object>();

            dic.Add("tag", tagMoel);
            var json    = JsonConvert.SerializeObject(dic);
            var tagPost = HttpRequest.Post(url, json);
            var result  = JsonConvert.DeserializeObject <TagObj>(tagPost);

            if (result.tag == null)
            {
                rm.IsSuccess = false;
                rm.msg       = "创建标签失败,错误码" + result.errcode + "," + result.errmsg + "";
            }
            rm.IsSuccess = true;
            rm.result    = result.tag.id;
            return(rm);
        }
示例#9
0
 public async Task <IActionResult> Post(CreateTag command)
 => await SendAsync(command.BindId(c => c.Id),
                    resourceId : command.Id, resource : "tags");