public async Task <ActionResult> Create([Bind(Include = "Id,Name,CommentText")] ContactComment contactComment) { if (!ModelState.IsValid) { return(View(contactComment)); } StringBuilder sbCommentText = new StringBuilder(); // HTML Encode the CommentText sbCommentText.Append(HttpUtility.HtmlEncode(contactComment.CommentText)); // Decode <b> and <u> sbCommentText.Replace("<b>", "<b>"); sbCommentText.Replace("</b>", "</b>"); sbCommentText.Replace("<u>", "<u>"); sbCommentText.Replace("</u>", "</u>"); contactComment.CommentText = sbCommentText.ToString(); // HTML Encode the Name string strEncodedName = HttpUtility.HtmlEncode(contactComment.Name); contactComment.Name = strEncodedName; db.ContactComments.Add(contactComment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult CreateContactComment(int contactId) { var comment = new ContactComment() { ContactId = contactId }; return(PartialView("_CreateOrEditContactComment", comment)); }
public async Task <ActionResult> DeleteConfirmed(int id) { ContactComment contactComment = await db.ContactComments.FindAsync(id); db.ContactComments.Remove(contactComment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult EditContactComment(ContactComment contactcomment) { if (ModelState.IsValid) { _commentRepo.InsertOrUpdateContactComments(contactcomment); _commentRepo.Save(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public void InsertOrUpdate(ContactComment contactcomment) { if (contactcomment.Id == default(int)) { // New entity context.ContactComments.Add(contactcomment); } else { // Existing entity context.Entry(contactcomment).State = EntityState.Modified; } }
// GET: ContactComment/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ContactComment contactComment = await db.ContactComments.FindAsync(id); if (contactComment == null) { return(HttpNotFound()); } return(View(contactComment)); }
public async Task <IActionResult> ContactComment(ContactCommentVM commentCommentVM) { ContactComment contactComment = new ContactComment() { Contact = _context.Contacts.Find(commentCommentVM.id), Name = commentCommentVM.name, Email = commentCommentVM.email, Subject = commentCommentVM.subject, Description = commentCommentVM.message }; await _context.ContactComments.AddAsync(contactComment); await _context.SaveChangesAsync(); return(RedirectToAction("Home", "Index")); }