Esempio n. 1
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task CreateAsync(ArticleCreateRequest request)
        {
            //生成文章id
            var id = await GetIdAsync();
            
            //初始化投票记录
            //作者默认投自己一票
            //一周内可投票
            var votedKey = string.Format(CacheConst.Voted, id);
            await RedisHelper.SAddAsync(votedKey, request.User);
            await RedisHelper.ExpireAsync(votedKey, CacheConst.OneWeekSeconds);

            var articleKey = string.Format(CacheConst.Article,id);
            var time = GetTimestamp(DateTime.Now);
            var articleArr = new object[]
            {
                "title",request.Title,
                "link",request.Link,
                "poster",request.User,
                "time",time,
                "votes",1
            };
            await  RedisHelper.HMSetAsync(articleKey, articleArr);
            
            //评分排序
            await RedisHelper.ZAddAsync(CacheConst.Score,(time + CacheConst.VoteScore,articleKey));
            //时间排序
            await RedisHelper.ZAddAsync(CacheConst.Time,(time,articleKey));
        }
Esempio n. 2
0
        public ActionResult AddConfirm(ArticleAddModel model)
        {
            var parameter = new ArticleCreateRequest(model.Title, model.Body, myId());
            var response  = bus.Handle(parameter);

            // You shoud return generated id from service or defivary notification object, if you wanna redirect to detail.
            return(RedirectToAction("MyList"));
        }
Esempio n. 3
0
 /// <summary>
 /// Erstellen eines neuen Produktes. <see cref="http://www.fastbill.com/api/produkte.html#article.create"/>
 /// </summary>
 public ApiResponse <ArticleCreateResponse> Create(ArticleCreateRequest request)
 {
     return(this.Send <ArticleCreateResponse>(new ApiRequest
     {
         Service = "article.create",
         Data = request
     }));
 }
Esempio n. 4
0
        public ArticleCreateResponse Handle(ArticleCreateRequest request)
        {
            var autherId = new UserId(request.AutherId);
            var id       = articleRepository.GenerateId();
            var article  = new Article(id, request.Title, request.Body, autherId);

            articleRepository.Save(article);
            return(new ArticleCreateResponse(id.Value));
        }
Esempio n. 5
0
        public async Task <IActionResult> CreateOne([FromBody] ArticleCreateRequest request)
        {
            var found = await _context.Projects.AnyAsync(x => x.Id == request.ProjectId);

            if (!found)
            {
                return(NotFound("Project wasn't found"));
            }

            var max = await _context.ConsumptionArticles.MaxAsync(x => x.Id);

            var art = _mapper.Map <ConsumptionArticle>(request);

            art.Id = max + 1;

            var res = await _context.ConsumptionArticles.AddAsync(art);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(CreateOne),
                                   await _context.ConsumptionArticles.ProjectTo <ArticleDetailResponse>(_mapper.ConfigurationProvider)
                                   .FirstOrDefaultAsync(x => x.Id == res.Entity.Id)));
        }
Esempio n. 6
0
        public async Task <IActionResult> CreateAsync([FromBody] ArticleCreateRequest request)
        {
            await ArticleService.CreateAsync(request);

            return(Ok());
        }