public JsonResult AddItemToCart(int id, string mySessionID) { if(mySessionID != null) { var myCart = ShoppingCartManager.getInstance().getMyShoppingCart(mySessionID); if(myCart == null) { myCart = new ShoppingCart(); myCart.Items = new List<Item>(); ShoppingCartManager.getInstance().addShoppingCartToList(myCart); } var newItem = new ItemBLL().GetById(id); if (newItem.InStock > 0) { myCart.Items.Add(newItem); myCart.SessionID = mySessionID; ShoppingCartManager.getInstance().updateCartTotalPrice(myCart); return this.Json(myCart); } } return null; }
public JsonResult GetMyUpdatedCartJSON() { var mySessionID = Session["SessionID"] as string; var myCart = ShoppingCartManager.getInstance().getMyShoppingCart(mySessionID); if (myCart == null) { myCart = new ShoppingCart(); myCart.Items = new List<Item>(); } myCart.SessionID = mySessionID; ShoppingCartManager.getInstance().updateCartTotalPrice(myCart); return this.Json(myCart); }
public void updateCartTotalPrice(ShoppingCart cart) { cart.PriceOfCart = cart.Items.Select(x => x.Price).Sum(); }
public void addShoppingCartToList(ShoppingCart newCart) { shoppingCarts.Add(newCart); }