public async Task <IActionResult> DeleteConfirmed(BookDeleteVm vm) { if (ModelState.IsValid) { var deleteBook = new BookDetails(); deleteBook.AuthorID = vm.AuthorId; deleteBook.Description = vm.Description; deleteBook.ISBN = vm.ISBN; deleteBook.Title = vm.Title; deleteBook.ID = vm.ID; try { bookservice.DeleteBookDetails(deleteBook, loanservice.GetLoansByBookId(vm.ID)); return(RedirectToAction(nameof(Index))); } catch (OperationCanceledException ex) { var test = ex; var message = ex.Message; ViewBag.message = ("You tried to delete a book that has books loaned out."); return(RedirectToAction(nameof(Index), new { ex = ViewBag.message })); } } return(RedirectToAction("Error", "Home", "")); }
public IActionResult Delete(BookDeleteVm vm) { var deletedBook = new BookDetails(); deletedBook.ID = vm.ID; deletedBook.Title = vm.Title; deletedBook.ISBN = vm.ISBN; deletedBook.Description = vm.Description; deletedBook.AuthorID = vm.AuthorID; bookService.DeleteBook(deletedBook); return(RedirectToAction(nameof(Index))); }
//GET: Delete public IActionResult Delete(int id) { var bookToDelete = bookService.GetBookById(id); var vm = new BookDeleteVm(); vm.ID = id; vm.ISBN = bookToDelete.ISBN; vm.Title = bookToDelete.Title; vm.AuthorID = bookToDelete.AuthorID; vm.Description = bookToDelete.Description; return(View(vm)); }
public ActionResult Delete(BookDeleteVm vm) { try { // Here we first check which of the delete options the user has clicked on // We also prevent the user from deleting a bookcopy that is part of a loan event if (vm.BookCopyId != 0 && vm.DeleteAll == false) { if (_bookCopyService.FindBookCopy(vm.BookCopyId).IsAvailable == false) { return(RedirectToAction(nameof(Delete), new { id = vm.BookDetailsID, bookCopyBlocked = true })); } else { _bookCopyService.DeleteBookCopy(vm.BookCopyId); return(RedirectToAction(nameof(Index))); } } else if (vm.BookCopyId == 0 && vm.DeleteAll) { var bookCopiesToBeRemoved = _bookCopyService.GetAllBookCopies().Where(b => b.DetailsId == vm.BookDetailsID).ToList(); var bookCopiesToBlock = bookCopiesToBeRemoved.Where(b => b.IsAvailable == false).ToList(); bookCopiesToBeRemoved.RemoveAll(b => b.IsAvailable == false); _bookCopyService.RemoveBookCopies(bookCopiesToBeRemoved); if (bookCopiesToBlock.Count() != 0) { return(RedirectToAction(nameof(Delete), new { id = vm.BookDetailsID, bookCopiesBlocked = true })); } else { _bookService.DeleteBookDetails(vm.BookDetailsID); return(RedirectToAction(nameof(Index))); } } else { return(RedirectToAction(nameof(Delete), vm.Book.ID)); } } catch (DbException) { return(View()); } }
//// GET: Books/Delete/5 public async Task <IActionResult> Delete(int id) { if (ModelState.IsValid) { var vm = new BookDeleteVm(); var book = bookservice.GetBook(id); vm.Title = book.Title; vm.Description = book.Description; vm.ISBN = book.ISBN; vm.AuthorId = book.AuthorID; vm.ID = book.ID; vm.Author = authorService.GetAuthor(book.AuthorID); return(View(vm)); } return(RedirectToAction("Error", "Home", "")); }
public ActionResult Delete(int id, bool bookCopiesBlocked, bool bookCopyBlocked) { if (id == 0) { return(NotFound()); } var vm = new BookDeleteVm(); vm.Book = _bookService.FindBook(id); vm.BookCopyList = new SelectList(_bookCopyService.GetAllBookCopies().Where(b => b.DetailsId == id).ToList(), "BookCopyId", "BookCopyId"); vm.BookCopiesBlocked = bookCopiesBlocked ? true : false; vm.BookCopyBlocked = bookCopyBlocked ? true : false; return(View(vm)); }