public IActionResult DeleteBook(int authorid, int id) { // Before deleting book, must check if book exists. if (!_bookLibraryRepository.AuthorExists(authorid)) { return(NotFound()); } var bookEntity = _bookLibraryRepository.GetBookForAuthor(authorid, id); if (bookEntity == null) { return(NotFound()); } _bookLibraryRepository.DeleteBook(bookEntity); if (!_bookLibraryRepository.Save()) { return(StatusCode(500, "A problem happend while handeling your request.")); } // Sending and email to developer notifying that a book has been deleted. _mailService.Send("Book deleted.", $"Book {bookEntity.Title} with id {bookEntity.Id} was deleted."); // Means that the request completed successfully but there is nothing to return. return(NoContent()); }
public IActionResult DeleteBookForAuthor(Guid authorId, Guid bookId) { if (!_bookLibraryRepository.AuthorExists(authorId)) { return(NotFound()); } var bookFromRepo = _bookLibraryRepository.GetBook(authorId, bookId); if (bookFromRepo == null) { return(NotFound()); } _bookLibraryRepository.DeleteBook(bookFromRepo); _bookLibraryRepository.Save(); return(NoContent()); }