public ActionResult PostComment(string msg, RatingViewModel model, int? id) { ViewBag.ansId = id; var v = _db.Answers.FirstOrDefault(m => m.AnswerId.Equals(id.Value)); if (v != null) ViewBag.quesTionid = v.QuestionId; ViewBag.id = id; TempData["HPostController"] = 7; var strList = new List<SensitiveWordsViewModel>(); var wdb = new WordDbContext(); if (Request.IsAuthenticated) { var u = _db.ForumUser.SingleOrDefault(m => m.UserName.Equals(User.Identity.Name)); if (u != null) { var userId = u.UserId; if (true) { var authUserId = u.UserId; var w = _db.Answers.SingleOrDefault(m => m.AnswerId.Equals(id.Value)); if (w != null) { var thisAnsUserId = w.UserId; if (authUserId == thisAnsUserId) { ViewData["EnableEdit"] = 1; } } if (msg != "") { var ms = ""; var sensitiveWods = wdb.Words.Select(m => m.SensitiveWord); var convt = msg.ToLower(); foreach (var str in sensitiveWods) { if (!convt.Contains(str.ToLower())) continue; var sensitive = new SensitiveWordsViewModel {SensitiveWords = str}; strList.Add(sensitive); ViewBag.senWordsMsg = 11; ms = str; } IEnumerable<SensitiveWordsViewModel> s = strList; ViewData["s"] = s; ViewData["op"] = 1; if (ms == "") { _comment.CommentMsg = msg; _comment.UserId = userId; if (id != null) { _comment.AnswerId = id.Value; _comment.PostedDateTime = DateTime.Now; _db.Comment.Add(_comment); _db.SaveChanges(); var t = _db.PostInformation.SingleOrDefault(m => m.UserId.Equals(userId)); if (t != null) { var posId = t.PostId; var totalCommentPost = _db.PostInformation.Find(posId).TotalCommentPost; if (totalCommentPost != null) { var prevPosts = totalCommentPost.Value; var pi = _db.PostInformation.Find(posId); pi.TotalCommentPost = prevPosts + 1; _db.Entry(pi).State = EntityState.Modified; } } _db.SaveChanges(); ViewBag.emptyBox = 1; UpdateTotalComments(id.Value); DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); } } if (id != null) { DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); } } else { if (id != null) { DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); } ViewData["op"] = 1; ViewData["ReqMsg"] = 1; ViewBag.errormsg = "* You must Write Something! to Post comment"; } } } } else { if (id != null) { DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); } ViewData["op"] = 1; ViewData["ReqMsg"] = 1; ViewData["c"] = 5; } try { var totalScore = _db.Rating.Where(m => m.AnswerId.Equals(id.Value)).Sum(m => m.RateScore); var totalRater = _db.Rating.Count(m => m.AnswerId.Equals(id.Value)); var avgScore = (double)totalScore / totalRater; ViewData["raiting"] = avgScore; } catch (Exception e) { } return View("Comments",model); }
public ActionResult PostComment(RatingViewModel mo, RatingViewModel model, string msg, int? id) { ViewData["op"] = 2; Comment comment = new Comment(); TempData["AreaFQAC"] = id; if (Request.IsAuthenticated) { if (id != null) { int userId = _db.ForumUser.SingleOrDefault(m => m.UserName.Equals(User.Identity.Name)).UserId; if (msg != "") { comment.CommentMsg = msg; comment.UserId = userId; comment.AnswerId = id.Value; comment.PostedDateTime = DateTime.Now; _db.Comment.Add(comment); _db.SaveChanges(); Response.Write("<div id='op'>"); Response.Write("</div>"); UpdateTotalComments(id.Value); DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); //return View("Comments"); } else { DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); ViewData["op"] = 2; ViewData["ReqMsg"] = 2; ViewBag.errormsg = "* You must Write Something! to Post comment"; return View("Comments"); } } else { int temId = _db.Temp.Single(x => x.Id.Equals(1)).Id; if (msg != "") { int useId = _db.ForumUser.SingleOrDefault(m => m.UserName.Equals(User.Identity.Name)).UserId; comment.CommentMsg = msg; comment.UserId = useId; comment.AnswerId = temId; comment.PostedDateTime = DateTime.Now; _db.Comment.Add(comment); _db.SaveChanges(); UpdateTotalComments(temId); DisplayAnswerAndPostedUserInfo(temId); DisplayComments(temId); //return View("Comments"); } else { DisplayAnswerAndPostedUserInfo(temId); DisplayComments(temId); ViewData["op"] = 2; ViewData["ReqMsg"] = 2; ViewBag.errormsg = "* You must Write Something! to Post comment"; return View("Comments"); } } } else { DisplayAnswerAndPostedUserInfo(id.Value); DisplayComments(id.Value); ViewData["op"] = 2; ViewData["ReqMsg"] = 1; ViewData["c"] = 6; return View("Comments"); } return View("Comments"); }