private void ActionVente() { int codeProduit; panier = new Panier(); do { Console.Write("Code produit : "); codeProduit = Convert.ToInt32(Console.ReadLine()); if (codeProduit != 0) { Produit produit = data.GetProduitById(codeProduit); if (produit != null) { panier.AddProduit(produit); data.DescStock(produit.Id); Console.WriteLine(produit); } else { Console.WriteLine("Aucun produit avec ce code"); } } else { Console.WriteLine("=========Panier=========="); Console.WriteLine(panier); data.SavePanier(panier); } } while (codeProduit != 0); clearConsole(); }
public bool SavePanier(Panier panier) { string request = "INSERT INTO panier (total) OUTPUT INSERTED.ID values (@total)"; command = new SqlCommand(request, connection); command.Parameters.Add(new SqlParameter("@total", panier.Total)); connection.Open(); panier.Id = (int)command.ExecuteScalar(); command.Dispose(); connection.Close(); if (panier.Id > 0) { panier.Produits.ForEach(p => SavePanierProduit(panier.Id, p.Id)); return(true); } return(false); }