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 })); }
public ActionResult Report(int?id, ItemType itemType, int?postid, string MsgContent, string type) { if (id.HasValue) { string hashtag = null; if (postid.HasValue) { hashtag = "#listpost" + postid; } string controller = itemType == ItemType.Topic ? "Topic" : "Blog"; string url = Url.Action("Details", controller, new { id = id }) + hashtag; string content = System.Net.WebUtility.HtmlEncode(MsgContent) + "<br>地址:<br><a href='" + url + "'>" + url + "</a>"; if (type == "rpt-author") { string author; if (itemType == ItemType.Topic) { var t = _db.Topics.Find(id.Value); author = t?.Author; } else { var blog = _db.Blogs.Find(id.Value); author = blog?.Author; } if (author == null) { return(NotFound()); } _msgUtil.AddMsg(User.Identity.Name, author, "汇报投稿问题", content); } else { _blogUtil.AddBlogPost(-1, User.Identity.Name, content); } return(Json(new { msg = "已成功汇报" })); } return(NotFound()); }
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 })); }