コード例 #1
0
        public ActionResult Create([Bind(Include = "id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,Name,CategoryId")] Article article)
        {
            if (ModelState.IsValid)
            {
                string   Id       = User.Identity.GetUserId();
                DateTime date     = DateTime.Now;
                Article  article1 = new Article()
                {
                    Name        = article.Name,
                    UserId      = Id,
                    CategoryId  = article.CategoryId,
                    ArticleDate = date
                };
                db.Articles.Add(article1);
                db.SaveChanges();
                ViewBag.Published = "The Article are Published";
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId     = new SelectList(db.AspNetUsers, "Id", "Email", article.UserId);
            ViewBag.CategoryId = new SelectList(db.Categories, "id", "Name", article.CategoryId);
            return(View(article));
        }
コード例 #3
0
        public ActionResult CreateComment([Bind(Include = "CommentName")] Comment comment)
        {
            string   UserId    = User.Identity.GetUserId();
            DateTime date      = DateTime.Now;
            int      Articleid = (int)Session["ArticleID"];
            Comment  comment1  = new Comment()
            {
                ArticleId   = Articleid,
                UserId      = UserId,
                CommentDate = date,
                CommentName = comment.CommentName
            };

            db.Comments.Add(comment1);
            db.SaveChanges();
            return(RedirectToAction("Index", "Articles"));
        }