public async Task <IActionResult> Comment(CommentViewModel comment) { var c = comment.GetComment((await _userManager.GetUserAsync(HttpContext.User)).Id); await _context.Comment.AddAsync(c); await _context.SaveChangesAsync(); //return to blog return(RedirectToAction(nameof(BlogShow), "Home", new{ id = comment.BlogId })); }
public ActionResult AddComment(CommentViewModel vm) { var comment = vm.GetComment(); var query = MongoDB.Driver.Builders.Query.EQ("_id", ObjectId.Parse(vm.PostId)); var post = Context.Posts.FindOne(query); post.Comments.Add(comment); Context.Posts.Save(post); ViewBag.Title = "Add Comment"; ViewBag.Status = string.Format("*** Post {0} has a new comment by {1} {2} ! ***", vm.PostId, comment.Author.FirstName, comment.Author.LastName); return(RedirectToAction("Index")); }