Exemplo n.º 1
0
        public ActionResult AddCommentToPost(int id, string commentContent)
        {
            AddCommentToPost model = new AddCommentToPost();

            model.selectedPost = id;
            //model.tags = db.Tags.ToList();
            ViewBag.PostTitle = db.Posts.Find(id).Title;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult AddCommentToPost(AddCommentToPost model)
        {
            string          username = User.Identity.GetUserName();
            ApplicationUser user     = db.Users.Where(u => u.UserName == username).FirstOrDefault();
            Comment         comment  = new Comment();

            comment.User    = user;
            comment.Author  = username;
            comment.Content = model.commentToAdd;
            db.Comments.Add(comment);
            db.SaveChanges();
            var post = db.Posts.Find(model.selectedPost);

            post.Comments.Add(comment);
            db.SaveChanges();
            return(RedirectToAction("Details/" + post.Id));
        }