public async Task <ActionResult> CheckOut() { if (!AccessToken.Valid()) { return(RedirectToAction("Login", "Account")); } Cart cart = GetCart(); Cart updatedCart = await bookstoreService.CheckOut(cart, AccessToken.Get()); if (updatedCart == null || updatedCart.CartItems.Count() == 0) { TempData["Cart_Error"] = true; TempData["Cart_Message"] = "Something Went Wrong"; return(RedirectToAction("Index", "Cart")); } Session["Cart"] = updatedCart; foreach (CartItem cartItem in updatedCart.CartItems) { if (!cartItem.IsAvailable) { ViewBag.Error = true; ViewBag.Message = "Not all items are available"; return(View("CheckOut", cart.CartItems)); } } return(View("CheckOut", cart.CartItems)); }
public async void CheckOut(Cart cart, BasicForm sender) { BookstoreService bookstoreService = new BookstoreService(); Cart updatedCart = await bookstoreService.CheckOut(Global.Cart, User.Token); if (updatedCart == null) { Global.MainForm.ShowUnauthorizedErrorMessage(); Global.CanCheckOut = false; return; } //assuming all items is available Global.CanCheckOut = true; foreach (CartItem item in updatedCart.CartItems) { if (!item.IsAvailable) { //if one item is not available then can not check out (show message) Global.CanCheckOut = false; } } ShowCheckOutForm(); }