public ActionResult Create(Comment comment) { StringBuilder sbComments = new StringBuilder(); // Encode the text that is coming from comments textbox sbComments.Append(HttpUtility.HtmlEncode(comment.Comments)); // Only decode bold and underline tags sbComments.Replace("<b>", "<b>"); sbComments.Replace("</b>", "</b>"); sbComments.Replace("<u>", "<u>"); sbComments.Replace("</u>", "</u>"); comment.Comments = sbComments.ToString(); // HTML encode the text that is coming from name textbox string strEncodedName = HttpUtility.HtmlEncode(comment.Name); comment.Name = strEncodedName; if (ModelState.IsValid) { db.Comments.Add(comment); db.SaveChanges(); return RedirectToAction("Index"); } return View(comment); }
// // GET: /Reader/AddComment public ActionResult AddComment(int id) { Comment com = new Comment(); com.PostId = id; com.DateCreated = DateTime.Now; return View(com); }
public ActionResult Receive(ILinkback linkback, int id) { Uri target_url = linkback is Pingback ? null : new Uri(Url.AbsoluteRouteUrl("Post", new { id })); IReceiveResult context = linkback.Receive(Request, target_url); if (context.Valid) { var comment = new Comment { Created = DateTime.Now, From = String.Format("{0} from {1}", linkback.Name, context.Url), Content = context.Excerpt ?? context.Title }; if (linkback is Pingback) { id = Int32.Parse(context.TargetUri.ToString().Substring(context.TargetUri.ToString().LastIndexOf("/") + 1)); } var post = _db.Post.First(x => x.Id == id); post.Comments.Add(comment); _db.SaveChanges(); } linkback.SendResponse(Response); return new EmptyResult(); }
public ActionResult AddComment(Comment c) { if (ModelState.IsValid) { if (ModelState.IsValid) { c.DateCreated = DateTime.Now; db.Comments.Add(c); db.SaveChanges(); return RedirectToAction("Index"); } } return View(c); }
public ActionResult Edit(Comment comment) { if (ModelState.IsValid) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(comment); }