// GET: BookController/Edit/5 public ActionResult Edit(int id) { try { var spec = new BooksWithAuthorsSpecification(id); var book = bookRepository.GetEntityWithSpec(spec); var authorId = book.Author == null ? book.Author.Id = 0 : book.Author.Id; var model = new BookAuthorViewModel { BookId = book.Id, Title = book.Title, Description = book.Description, AuthorId = authorId, Authors = authorRepository.List().ToList(), ImageUrl = book.ImageUrl }; return(View(model)); } catch (Exception) { return(View()); } }
// GET: BookController public ActionResult Index() { var spec = new BooksWithAuthorsSpecification(); var books = bookRepository.List(spec); return(View(books)); }
// GET: BookController/Details/5 public ActionResult Details(int id) { var spec = new BooksWithAuthorsSpecification(id); var book = bookRepository.GetEntityWithSpec(spec); return(View(book)); }
// GET: BookController/Search public ActionResult Search(string term) { try { var spec = new BooksWithAuthorsSpecification(term); var books = bookRepository.List(spec); return(View("Index", books)); } catch { return(View()); } }