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("&lt;b&gt;", "<b>");
            sbComments.Replace("&lt;/b&gt;", "</b>");
            sbComments.Replace("&lt;u&gt;", "<u>");
            sbComments.Replace("&lt;/u&gt;", "</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);
        }
예제 #2
0
 //
 // GET: /Reader/AddComment
 public ActionResult AddComment(int id)
 {
     Comment com = new Comment();
     com.PostId = id;
     com.DateCreated = DateTime.Now;
     return View(com);
 }
예제 #3
0
        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();
        }
예제 #4
0
        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);
 }