//[Authorize] public IActionResult CheckOut(Order order) { var items = _shopingCart.GetShopingCartItems(); _shopingCart.ShopingCartItems = items; if (order == null) { throw new NullReferenceException(); } if (_shopingCart.ShopingCartItems.Count == 0) { ModelState.AddModelError("", "Cart is Empty. Add some Books first."); } if (ModelState.IsValid) { order.OrderedPlaced = DateTime.Now; order.OrderTotal = _shopingCart.GetShopingCartTotal(); _orderRepository.CreateOrder(order); _shopingCart.ClearCart(); return(Json(new { success = true, message = "Saved Successfull" })); } return(Json(new { success = false, message = "Saved Unsuccessfull" })); }
public RedirectToActionResult ClearCart() { if (_shopingCart.ShopingCartItems != null) { _shopingCart.ShopingCartItems = _shopingCart.GetShopingCartItems(); } _shopingCart.ClearCart(); return(RedirectToAction("Index")); }
public IActionResult CheckOut(Order order) { var items = _shopingCart.GetShopingCartItems(); _shopingCart.ShopingCartItems = items; if (_shopingCart.ShopingCartItems.Count == 0) { ModelState.AddModelError("", "Cart is Empty. Add some Books first."); } if (ModelState.IsValid) { order.OrderedPlaced = DateTime.Now; order.OrderTotal = _shopingCart.GetShopingCartTotal(); _orderRepository.CreateOrder(order); _shopingCart.ClearCart(); return(RedirectToAction("CheckoutComplete")); } return(View()); }