//异步提交评论 public JsonResult SubComment() { //先判断登录 int?userId = WebHelper.GetUserIdInSession(); if (userId == null || userId.Value <= 0) { return(Json(new { Status = "error", Data = "" }, JsonRequestBehavior.AllowGet)); } //新增评论 ChapterCommentBLL commentBll = new ChapterCommentBLL(); DateTime now = DateTime.Now; ChapterComment comment = new ChapterComment(); comment.ChapterId = Convert.ToInt32(Request["chapterId"]); comment.Comment = Request["comment"]; comment.PostTime = now; comment.UserId = userId.Value; int id = commentBll.AddComment(comment); User user = new UserBLL().GetById(userId.Value); return(Json(new { Status = "ok", Id = id, Time = now.ToString("yyyy-MM-ddTHH:mm:ss"), //2016-05-16T22:34:28 UserName = user.UserName, }, JsonRequestBehavior.AllowGet)); }
//获取文章的评论 public JsonResult GetComments() { int chapterId = Convert.ToInt32(Request["id"]); ChapterCommentBLL commentBll = new ChapterCommentBLL(); List <ChapterComment> commentList = commentBll.GetCommentsByCId(chapterId); string jsonData = JsonConvert.SerializeObject(commentList); return(Json(new { count = commentList.Count, comments = jsonData }, JsonRequestBehavior.AllowGet)); }