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