public ActionResult CreateComment(string id) { var aPost = _dataRepository.GetAPostWithId(id); var vm = new CommentViewModel(); vm.ThePost = aPost; vm.ThePostId = id; return View("CreatePostComment", vm); }
public void AddComment(CommentViewModel aCommentvm) { var thePost = GetAPostWithId(aCommentvm.ThePostId); var aNewComment = new Comment { Body = aCommentvm.Body, Email = aCommentvm.Email, TimePosted = DateTime.Now }; thePost.Comments.Add(aNewComment); _collection.Save(thePost); }
public ActionResult CreateComment(CommentViewModel vm) { try { vm.TimePosted = DateTime.Now; _dataRepository.AddComment(vm); //Post aPost =_dataRepository.GetAPostWithId(postId); return RedirectToAction("Details", new {id = vm.ThePostId}); } catch { return View("Index"); } }