Beispiel #1
0
        public ActionResult AddReplyWithRate(int itemid, string addreplycontent, string Captcha, string Prefix, int?rating)
        {
            Post post;

            try
            {
                CheckPost(Captcha, Prefix, addreplycontent);
                UsersRating userrate = null;
                if (rating != null && RatingUtil.RatingValue.ContainsKey(rating.Value))
                {
                    userrate = _ratingUtil.GetUsersRating(itemid);
                    if (userrate.Rating != null && (userrate.HasPost || userrate.Rating.value != RatingUtil.RatingValue[rating.Value]))
                    {
                        throw new BlogException(userrate.RateWithAccount ? "您已经评过分了" : "今天已经评过分了");
                    }
                }
                post = _blogUtil.AddBlogPost(itemid, User.Identity.Name, _sanitizerService.Sanitize(addreplycontent));
                HttpContext.Session.SetDateTime("LastPostTime", DateTime.Now);
                if (userrate != null)
                {
                    if (userrate.Rating == null)
                    {
                        var Rate = _ratingUtil.AddBlogRating(itemid, rating.Value, userrate.credential, post.PostId);
                        if (Rate != null)
                        {
                            _ratingUtil.getRating(itemid, false);
                        }
                    }
                    else
                    {
                        userrate.Rating.PostId = post.PostId;
                        _db.SaveChanges();
                    }
                }
                TriggerAddPost(post);
            }
            catch (BlogException e)
            {
                return(Json(new { err = e.Message }));
            }
            string expmsg = HttpContext.Items["QuestMsg"] as string;

            return(Json(new { id = post.PostId, expmsg }));
        }
Beispiel #2
0
 public ActionResult GetRate(int blogid)
 {
     return(Json(new { rating = _ratingUtil.getRating(blogid, false) }));
 }
Beispiel #3
0
        public async Task <ActionResult> Comment([FromBody] AddCommentRequest request)
        {
            if (string.IsNullOrWhiteSpace(BlogHelper.removeAllTags(request.Content)))
            {
                return(BadRequest(new { error = "内容不能为空或纯图片。" }));
            }
            Post post;

            switch (request.Type)
            {
            case Models.App.Comment.CommentType.Blog:
                var blog = await _db.Blogs.Include("option").SingleOrDefaultAsync(b => b.BlogID == request.ItemId);

                if (blog == null)
                {
                    return(NotFound());
                }
                if (blog.option != null && blog.option.NoComment)
                {
                    return(Forbid());
                }
                UsersRating userrate = null;
                if (request.Rating != null && RatingUtil.RatingValue.ContainsKey(request.Rating.Value))
                {
                    if (blog.option.NoRate)
                    {
                        return(Forbid());
                    }
                    userrate = _ratingUtil.GetUsersRating(request.ItemId);
                    if (userrate.Rating != null && (userrate.HasPost || userrate.Rating.value != RatingUtil.RatingValue[request.Rating.Value]))
                    {
                        return(BadRequest(new { error = userrate.RateWithAccount ? "您已经评过分了" : "今天已经评过分了" }));
                    }
                }
                post = _blogUtil.AddBlogPost(request.ItemId, User.Identity.Name, _sanitizerService.Sanitize(request.Content));
                if (userrate != null)
                {
                    if (userrate.Rating == null)
                    {
                        var Rate = _ratingUtil.AddBlogRating(request.ItemId, request.Rating.Value, userrate.credential, post.PostId);
                        if (Rate != null)
                        {
                            _ratingUtil.getRating(request.ItemId, false);
                        }
                    }
                    else
                    {
                        userrate.Rating.PostId = post.PostId;
                        await _db.SaveChangesAsync();
                    }
                }
                break;

            default:
                return(BadRequest());
            }
            TriggerAddPost(post);
            string expmsg = HttpContext.Items["QuestMsg"] as string;

            return(Json(new AddReplyResponse {
                CommentId = post.PostId, Message = expmsg
            }));
        }