diff --git a/SportsStore/SportsStore.WebUI/Controllers/CartController.cs b/SportsStore/SportsStore.WebUI/Controllers/CartController.cs index 7b41c1e..fc6286a 100644 --- a/SportsStore/SportsStore.WebUI/Controllers/CartController.cs +++ b/SportsStore/SportsStore.WebUI/Controllers/CartController.cs @@ -12,10 +12,12 @@ namespace SportsStore.WebUI.Controllers public class CartController : Controller { private IProductRepository repository; + private IOrderProcessor orderProcessor; - public CartController(IProductRepository repo) + public CartController(IProductRepository repo, IOrderProcessor proc) { repository = repo; + orderProcessor = proc; } public ViewResult Index(Cart cart, string returnUrl) @@ -57,9 +59,30 @@ namespace SportsStore.WebUI.Controllers return PartialView(cart); } + // GET public ViewResult Checkout() { return View(new ShippingDetails()); } + + // POST + [HttpPost] + public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails) + { + if (cart.Lines.Count() == 0) + { + ModelState.AddModelError("", "Sorry, your cart is empty"); + } + if (ModelState.IsValid) + { + orderProcessor.ProcessOrder(cart, shippingDetails); + cart.Clear(); + return View("Completed"); + } + else + { + return View(shippingDetails); + } + } } } \ No newline at end of file