public async Task<JsonResult> Add(int id)
        {
            try
            {
                var products = await ApiHelpers.LoadAsync<Product>("api/products");
                var orderedProduct = new OrderedProduct(products.FirstOrDefault(p => p.ProductId == id));

                SessionCart.Add(orderedProduct);

                return Json(new {ok = true, itemcount = SessionCart.ItemCount, totalcart = SessionCart.Total});
            }
            catch (Exception ex)
            {
                //TODO Log exception
                return Json(null);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Add a product to the cart.
 /// </summary>
 /// <param name="orderedProduct">The product to add.</param>
 public void Add(OrderedProduct orderedProduct)
 {
     orderedProduct.CartProductId = Guid.NewGuid().ToString();
     _products.Add(orderedProduct);
 }