public void Can_Be_Cleared()
 {
     Cart cart = new Cart();
     cart.AddItem(new Product(), 1);
     Assert.AreEqual(1, cart.Lines.Count);
     cart.Clear();
     Assert.AreEqual(0, cart.Lines.Count);
 }
 public ViewResult CheckOut(Cart cart, FormCollection form)
 {
     if(cart.Lines.Count == 0)
     {
         ModelState.AddModelError("Cart", "Sorry, your cart is empty!");
         return View();
     }
     if (TryUpdateModel(cart.ShippingDetails, form.ToValueProvider()))
     {
         orderSubmitter.SubmitOrder(cart);
         cart.Clear();
         return View("Completed");
     }
     else
         return View();
 }
Exemple #3
0
        public ViewResult CheckOut(Cart cart, FormCollection form)
        {
            // Empty carts can't be checked out
            if(cart.Lines.Count == 0) {
                ModelState.AddModelError("Cart", "Sorry, your cart is empty!");
                return View();
            }

            // Invoke model binding manually
            if (TryUpdateModel(cart.ShippingDetails, form.ToValueProvider())) {
                orderSubmitter.SubmitOrder(cart);
                cart.Clear();
                return View("Completed");
            }
            else // Something was invalid
                return View();
        }