public IActionResult Buy(string id) { ServiceProduct serviceProduct = new ServiceProduct(); if (SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart") == null) { List <Item> cart = new List <Item>(); cart.Add(new Item { Product = serviceProduct.FindProduct(id), Quantity = 1 }); SessionHelper.setObjectAsJson(HttpContext.Session, "cart", cart); } else { List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); int index = isExist(id); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new Item { Product = serviceProduct.FindProduct(id), Quantity = 1 }); } SessionHelper.setObjectAsJson(HttpContext.Session, "cart", cart); } return(RedirectToAction("Index")); }