Esempio n. 1
0
        public void ProductSelection()
        {
            Console.WriteLine();
            Console.Write("Please enter the product code you'd like to add to your cart: ");
            string desiredItem = Console.ReadLine();

            foreach (CateringItem listItem in catering.fileAccess.menu)
            {
                if (listItem.ItemCode.ToLower() == desiredItem.ToLower())
                {
                    Console.Write("Please enter the quantity you would like to purchase: ");
                    int desiredQty = int.Parse(Console.ReadLine());
                    Console.WriteLine();
                    if (listItem.ItemQty != "SOLD OUT")
                    {
                        if (int.Parse(listItem.ItemQty) >= desiredQty)
                        {
                            catering.AddToShoppingCart(desiredItem, desiredQty);
                            fileAccess.WriteReceipt(desiredItem, desiredQty, catering);
                            Console.WriteLine($"You have successfully added {listItem.ItemName} (Qty {desiredQty}) to your cart.");
                            Console.WriteLine("(1) Return To Main Menu");
                            Console.WriteLine("(2) Add Another Item");
                            string userInput = Console.ReadLine();
                            switch (userInput)
                            {
                            case "1":
                                MainMenu();
                                break;

                            case "2":
                                ProductSelection();
                                break;

                            default:
                            {
                                Console.WriteLine("This not a valid selection. Please type '1' or '2'.");
                            }
                            break;
                            }
                        }
                        else if (int.Parse(listItem.ItemQty) < desiredQty)
                        {
                            Console.WriteLine("There is not enough of this product in stock to purchase.");
                            Console.WriteLine("(1) Return To Main Menu");
                            Console.WriteLine("(2) Add Another Item");
                            string userInput = Console.ReadLine();
                            switch (userInput)
                            {
                            case "1":
                                MainMenu();
                                break;

                            case "2":
                                ProductSelection();
                                break;

                            default:
                            {
                                Console.WriteLine("This not a valid selection. Please type '1' or '2'.");
                            }
                            break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("This item is sold out.");
                        Console.WriteLine("(1) Return To Main Menu");
                        Console.WriteLine("(2) Add Another Item");
                        string userInput = Console.ReadLine();
                        switch (userInput)
                        {
                        case "1":
                            MainMenu();
                            break;

                        case "2":
                            ProductSelection();
                            break;

                        default:
                        {
                            Console.WriteLine("This not a valid selection. Please type '1' or '2'.");
                        }
                        break;
                        }
                    }
                }
            }
        }