public IActionResult Take(int id) { var book = _bookRepository.GetById(id); if (book == null) { return(NotFound()); } var readers = _readerRepository.GetAll(); var vm = new TakeBookViewModel { Book = _mapper.Map <BookViewModel>(book), Readers = _mapper.Map <IEnumerable <ReaderViewModel> >(readers) }; return(View(vm)); }
public IActionResult Take(TakeBookViewModel model) { if (ModelState.IsValid) { try { _bookService.GiveBook(model.Book.Id, model.Reader.Id); return(RedirectToAction("MyBooks", "Reader", new { id = model.Reader.Id })); } catch (NotFoundException) { ModelState.AddModelError("", "Ошибка"); return(View(model)); } catch (NoAvailableBooksException) { ModelState.AddModelError("", "Нельзя взять эту книгу!"); return(View(model)); } } return(View(model)); }