コード例 #1
0
 public ActionResult <List <AuthorModel> > Get()
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         return(myDbManager.GetAllAuthors());
     }
 }
コード例 #2
0
 public ActionResult <AuthorModel> Get(int id)
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         if (myDbManager.GetAnAuthor(id) == null)
         {
             return(NotFound());
         }
         return(myDbManager.GetAnAuthor(id));
     }
 }
コード例 #3
0
 [HttpDelete("{id}")]  // call by Postman
 public ActionResult <Author> Delete(int id)
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         bool isDeleted = myDbManager.DeleteAuthor(id);
         if (isDeleted)
         {
             return(Ok("Author is deleted."));
         }
         else
         {
             return(NotFound());
         }
     }
 }
コード例 #4
0
 [HttpPut("{id}")]  // call by Postman
 public IActionResult Put(int id, AuthorModel author)
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         bool isEdited = myDbManager.EditAuthotr(id, author);
         if (isEdited)
         {
             return(NoContent());
         }
         else
         {
             return(NotFound());
         }
     }
 }
コード例 #5
0
 [HttpPost]  // call by Postman
 public ActionResult <string> Post(AuthorModel author)
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         bool isAdded = myDbManager.AddAuthor(author);
         if (isAdded)
         {
             return(Ok("Ok"));
         }
         else
         {
             return(BadRequest());
         }
     }
 }