public JsonResult UpdateTotal() { decimal total; try { var cartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID); total = cartItems.Select(p => p.UnitPrice * p.Quantity).Sum(); } catch (Exception) { total = 0; } return(Json(new { d = String.Format("{0:c}", total) }, JsonRequestBehavior.AllowGet)); }
// GET: Checkout public ActionResult Index() { if (Session["ExpressShip"] == null) { Session["ExpressShip"] = false; } ShoppingBag(); var currentUserCartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID); ViewBag.Cart = currentUserCartItems; decimal total = 0; if (currentUserCartItems != null && currentUserCartItems.Any()) { total = currentUserCartItems.Select(p => p.UnitPrice * p.Quantity).Sum(); } ViewBag.CartTotalPrice = total; return(View()); }