Example #1
0
        // GET: Cart
        public ActionResult Cart()
        {
            var cartViewModel = new CartViewModel
            {
                BookOrders = OrderRepository.RetrieveAllOrders()
            };

            return View("Cart", cartViewModel);
        }
Example #2
0
        public ActionResult Cart(CartViewModel cartViewModel)
        {
            // Get the book session data
            var bookViewModel = (BookViewModel) Session["BookData"];

            // Check for valid number of copies
            if (cartViewModel.NumCopies < 1)
                ModelState.AddModelError("NumCopies", "Quantity must be greater than zero");


            if (!ModelState.IsValid)
                return View("Index", bookViewModel);

            // Create a new book order with the selected book
            var order = new Order(BookRepository.GetBookById(bookViewModel.BookId), cartViewModel.NumCopies);

            // Save the order to the repository
            OrderRepository.SaveOrder(order);

            cartViewModel.BookOrders = OrderRepository.RetrieveAllOrders();

            return RedirectToAction("Cart", cartViewModel);
        }