コード例 #1
0
ファイル: HomeController.cs プロジェクト: pho35/phonoombu
 public ActionResult DetailPostComments(int id = 0)
 {
     LstCommentsByPost myLstCommentsByPost = new LstCommentsByPost();
     myLstCommentsByPost.postConcerned = db.Posts.Find(id);
     if (myLstCommentsByPost.postConcerned == null)
     {
         return HttpNotFound();
     }
     return View(myLstCommentsByPost);
 }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: pho35/phonoombu
 public ActionResult DetailPostComments(LstCommentsByPost lstCommentsByPost, int id)
 {
     if (ModelState.IsValid)
     {
         User userAuthor = db.Users.Find(WebSecurity.CurrentUserId);
         Post postConcerned = db.Posts.Find(id);
         Comment newComs = new Comment()
         {
             CommentAuthor = userAuthor,
             CommentContent = lstCommentsByPost.unComment.CommentContent,
             PostConcerned = postConcerned,
             DatePublication = DateTime.Today
         };
         db.Comments.Add(newComs);
         userAuthor.MyLstComment.Add(newComs);
         postConcerned.Comments.Add(newComs);
         db.SaveChanges();
         return RedirectToAction("DetailPostComments", "Home", new { id = postConcerned.PostId });
     }
     else
     {
         return View(lstCommentsByPost);
     }
 }