private static void ChooseFood(List <food> groceries, Person client) { Console.WriteLine("What do you want to buy?"); string foodName = Console.ReadLine(); food chosenFood = groceries.FirstOrDefault(x => x.Name == foodName); if (chosenFood == null) { Console.WriteLine("Excuse me, we dont't have" + foodName + "in our shop."); } else { Console.WriteLine("How much?"); string amount = Console.ReadLine(); int a; bool success = int.TryParse(amount, out a); while (!success) { Console.WriteLine("Escuse me, amount should be integer value: "); amount = Console.ReadLine(); success = int.TryParse(amount, out a); } client.ShoppingCart.AddToCart(chosenFood, a); } Console.WriteLine("Anything else? Y/N"); }
public void AddToCart(food food, int amount) { Items.Add(food); Amounts.Add(amount); }