예제 #1
0
        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("&lt;b&gt;", "<b>");
            sbCommentText.Replace("&lt;/b&gt;", "</b>");
            sbCommentText.Replace("&lt;u&gt;", "<u>");
            sbCommentText.Replace("&lt;/u&gt;", "</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"));
        }
예제 #2
0
        public ActionResult CreateContactComment(int contactId)
        {
            var comment = new ContactComment()
            {
                ContactId = contactId
            };

            return(PartialView("_CreateOrEditContactComment", comment));
        }
예제 #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            ContactComment contactComment = await db.ContactComments.FindAsync(id);

            db.ContactComments.Remove(contactComment);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #4
0
 public ActionResult EditContactComment(ContactComment contactcomment)
 {
     if (ModelState.IsValid)
     {
         _commentRepo.InsertOrUpdateContactComments(contactcomment);
         _commentRepo.Save();
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }
예제 #5
0
 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;
     }
 }
예제 #6
0
        // 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"));
        }