/// <summary>
 /// Create a new Products object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 public static Products CreateProducts(global::System.String id, global::System.Double price)
 {
     Products products = new Products();
     products.ID = id;
     products.Price = price;
     return products;
 }
 /// <summary>
 /// Create a new Products object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static Products CreateProducts(global::System.String id)
 {
     Products products = new Products();
     products.ID = id;
     return products;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Products products)
 {
     base.AddObject("Products", products);
 }
        public ActionResult Index(List<string> IDProduct, List<string> Quantity)
        {
            int i=0;
              int j = 0;
              string IDPrtChoose=null;
              string QuantityPrtChoose=null;
            foreach (string quantityProduct in Quantity)
            {

                if (quantityProduct != "")
                {
                    foreach (string IDPrd in IDProduct)
                    {
                        if (i == j)
                        {
                            IDPrtChoose = IDPrd;
                            QuantityPrtChoose = quantityProduct;
                            break;
                        }
                        j++;
                    }
                }
                i++;
            }

            // ho considerato id numerico, l' avrei potuto anche definire tipo string

                var moveToChart = (from m in _db.Products where m.ID == IDPrtChoose select m).First();
                var AddToChart = (from m in _db.Products where m.ID == moveToChart.ID select m).First();

                if (Session["ListChart"] == null)
                {
                    listChart = new List<Products>();
                    prodChart = (Products)AddToChart;

                    listChart.Add(prodChart);

                    Session["ListChart"] = listChart;

                }

                else
                {
                    listChart = (List<Products>)Session["ListChart"];
                    Products addProduct = (Products)AddToChart;

                    listChart.Add(addProduct);
                    Session["ListChart"] = listChart;
                }

                quantityProdChart = new ChartClass();

                int qntProd = Int32.Parse(QuantityPrtChoose);
                quantityProdChart.Title = moveToChart.Title;
                quantityProdChart.IDProduct = moveToChart.ID;
                if (Session["PriceProduct"] == null)
                {
                    listQuantityProduct = new List<ChartClass>();
                    quantityProdChart.Quantity = qntProd;

                    quantityProdChart.PriceSingProduct = moveToChart.Price.Value;
                    quantityProdChart.TotPriceAllProduct += quantityProdChart.PriceSingProduct * quantityProdChart.Quantity;

                    listQuantityProduct.Add(quantityProdChart);
                    Session["PriceProduct"] = listQuantityProduct;

                }

                else
                {

                    listQuantityProduct = (List<ChartClass>)Session["PriceProduct"];

                    quantityProdChart.Quantity = qntProd;

                    bool boolVerif = false;
                    foreach (var item in listQuantityProduct)
                    {
                        if (item.IDProduct == moveToChart.ID)
                        {
                            item.Quantity += qntProd;
                            item.PriceSingProduct = moveToChart.Price.Value;
                            item.TotPriceAllProduct += (Double)moveToChart.Price * quantityProdChart.Quantity;
                            boolVerif = true;
                        }
                    }
                    if (boolVerif == false)
                    {

                        quantityProdChart.Title = moveToChart.Title;
                        quantityProdChart.PriceSingProduct = moveToChart.Price.Value;
                        //quantityProdChart.TotPriceSingProduct = (Double)moveToChart.Price * quantityProdChart.PriceSingProduct;
                        quantityProdChart.TotPriceAllProduct += (Double)moveToChart.Price * quantityProdChart.Quantity;

                        listQuantityProduct.Add(quantityProdChart);

                    }

                }

                Session["PriceProduct"] = listQuantityProduct;

            return View(_db.Products.ToList());
        }