Exemplo n.º 1
0
 public ActionResult <List <AuthorModel> > Get()
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         return(myDbManager.GetAllAuthors());
     }
 }
Exemplo n.º 2
0
 public ActionResult <AuthorModel> Get(int id)
 {
     using (DbAuthorManager myDbManager = new DbAuthorManager())
     {
         if (myDbManager.GetAnAuthor(id) == null)
         {
             return(NotFound());
         }
         return(myDbManager.GetAnAuthor(id));
     }
 }
Exemplo n.º 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());
         }
     }
 }
Exemplo n.º 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());
         }
     }
 }
Exemplo n.º 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());
         }
     }
 }