コード例 #1
0
 public ActionResult Post([FromBody] Comment Comment)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         db.Comments.Add(Comment);
         db.SaveChanges();
         return(CreatedAtAction("Post", new { id = Comment.CommentId }, Comment));
     }
 }
コード例 #2
0
 public ActionResult Post([FromBody] Category category)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         db.Categories.Add(category);
         db.SaveChanges();
         return(CreatedAtAction("Post", new { id = category.CategoryId }, category));
     }
 }