Пример #1
0
        public ActionResult Rate(string blogid, string rating)
        {
            int    id     = int.Parse(blogid);
            int    value  = int.Parse(rating);
            string status = _ratingUtil.TryRateBlog(id, value);

            if (status == "login")
            {
                return(Json(new { errmsg = "请登录后再评分!" }));
            }
            else if (status == "rated")
            {
                return(Json(new { errmsg = "您已经评过分了!" }));
            }
            else if (status == "rated_today")
            {
                return(Json(new { errmsg = "今天已经评过分了!" }));
            }
            else if (status == "error")
            {
                return(Json(new { errmsg = "无效的评分,请刷新重试" }));
            }
            var total = _ratingUtil.GetRating(id, false);

            if (HttpContext.Items["QuestMsg"] is string QuestMsg)
            {
                return(Json(new { rating = total, msg = QuestMsg }));
            }
            return(Json(new { rating = total }));
        }
Пример #2
0
        public async Task <IActionResult> Rate(RateRequest req)
        {
            var blog = await db_.Blogs.Include(b => b.option).SingleOrDefaultAsync(b => b.BlogID == req.BlogId);

            if (blog == null)
            {
                return(NotFound());
            }
            if (blog.option != null && blog.option.NoRate)
            {
                return(Forbid());
            }
            string status = ratingUtil_.TryRateBlog(req.BlogId, req.Rating);

            if (status != "ok")
            {
                return(BadRequest(new { error = status }));
            }
            return(Json(new RateResponse {
                Status = status,
                Message = HttpContext.Items["QuestMsg"] as string,
                Rating = ratingUtil_.GetRating(req.BlogId, false)
            }));
        }