public ActionResult AddComment(Comment comment, string postId) { var post = (from p in _postRepository.Find() where p.Id == postId select p).FirstOrDefault(); if (post != null) { _postRepository.AddComment(post, comment); } return View("Detail", post); }
public void AddComment(Post post, Comment comment) { if (post.Id == null) { throw new InvalidOperationException("Post has no ID"); } if (post.Comments == null) { post.Comments = new List<Comment>(); } post.Comments.Add(comment); _collection.Save(post); }