コード例 #1
0
ファイル: CommentsController.cs プロジェクト: shayshu11/Blog
        public ActionResult Create([Bind(Include = "ID,Content,Title")] Comment comment)
        {
            // Check if a user is logged in
            if (ShaulisBlog.Controllers.LoginController.IsFanLoggedIn())
            {
                if (ModelState.IsValid)
                {
                    comment.CommentDate = DateTime.Now;
                    comment.WriterId    = LoginController.getUserId();
                    comment.PostId      = currPostId;
                    db.Comments.Add(comment);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "BlogPosts"));
                }

                ViewBag.WriterId = new SelectList(db.Fans, "ID", "FirstName", comment.WriterId);
                ViewBag.PostId   = new SelectList(db.BlogPosts, "ID", "Content", comment.PostId);
                return(View(comment));
            }

            return(RedirectToAction("Login", "Login"));
        }