public JsonResult CommentDelete(int id) { JsonResult rez = new JsonResult(); Comment cmn = new Comment() { Id = id }; con.Entry(cmn).State = System.Data.EntityState.Deleted; con.SaveChanges(); rez.Data = "Коментарий удален.;true"; return rez; }
public JsonResult AddComment(Comment cmt) { JsonResult rez = new JsonResult(); if (ModelState.IsValid && (User.Identity.IsAuthenticated || this.IsCaptchaVerify("Captcha is not valid"))) { try { con.Comments.Add(cmt); con.SaveChanges(); rez.Data = RenderPartialViewToString("CommentRead", cmt); } catch (Exception e) { rez.Data = e.Message; } } else { foreach (var item in ModelState.Keys) for (int i = 0; i < ModelState[item].Errors.Count; i++) rez.Data += ModelState[item].Errors[i].ErrorMessage + "\r\n"; } return rez; }