public IActionResult Buy(string id) { PizzaModel pizzaModel = new PizzaModel(); if (SessionHelper.GetObjectFromJson <List <CartItem> >(HttpContext.Session, "cart") == null) { List <CartItem> cart = new List <CartItem>(); cart.Add(new CartItem { Pizza = pizzaModel.find(id), Quantity = 1 }); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { List <CartItem> cart = SessionHelper.GetObjectFromJson <List <CartItem> >(HttpContext.Session, "cart"); int index = isExist(id); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new CartItem { Pizza = pizzaModel.find(id), Quantity = 1 }); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } return(RedirectToAction("Index")); }