public async Task <IActionResult> OnPost(int bookId) { var book = await _booksInfoContext.BooksList.SingleAsync(b => b.Id == bookId); if (book != null) { _booksInfoContext.Remove(book); await _booksInfoContext.SaveChangesAsync(); } else { return(RedirectToPage("./NotFound")); } TempData["Message"] = $"{book.Title} deleted"; return(RedirectToPage("./List")); }
public async Task <IActionResult> OnPost(int authorId) { Author = await _infoContext.AuthorsList.SingleAsync(a => a.Id == authorId); var book = await _infoContext.BooksList.AnyAsync(b => b.AuthorInfoId == authorId); if (book == false) { _infoContext.Remove(Author); await _infoContext.SaveChangesAsync(); } else { TempData["Message"] = $"{Author.Id} can't be deleted"; return(RedirectToPage("./AuthorDetails")); } TempData["Message"] = $"{Author.FirstName} + {Author.LastName} was deleted"; return(RedirectToPage("./AuthorsList")); }