public ActionResult Index(BookViewModel bookViewModel) { // Repopulate Book Collection on post bookViewModel.BookData = BookRepository.GetAllBookData(); // Get book data from repo based on selected book in the view var book = BookRepository.GetBookById(bookViewModel.BookId); // Set the view model properties for the current book bookViewModel.Title = book.Title; bookViewModel.Description = book.Description; bookViewModel.Price = book.Price; // Store the bookViewModel in the session Session["BookData"] = bookViewModel; return View("Index", bookViewModel); }
// GET: Store public ActionResult Index() { // Get book data from repo var bookRepository = BookRepository.GetAllBookData(); // Remove already added books from the dropdown list foreach (var order in OrderRepository.RetrieveAllOrders()) { bookRepository.Remove(bookRepository.Single(b => b.Id == order.Book.Id)); } // Instantiate the viewmodel var bookViewModel = new BookViewModel { BookData = bookRepository }; return View("Index", bookViewModel); }