Exemplo n.º 1
0
        public void EnterQuantity()
        {
            Console.WriteLine($"You selected {drink.DrinkName}, which has {drink.ABV}% ABV and costs {drink.Price.ToString("c2")}");
            Console.WriteLine("How many would you like?");
            string          drinkQuantity       = Console.ReadLine();
            int             drinkQuantityNumber = int.Parse(drinkQuantity);
            List <Location> locations           = _inventoryBL.GetAvailableLocations(drink.DrinkName, drinkQuantityNumber);

            drink = _inventoryBL.GetDrinkByName(drink.DrinkName);
            if (locations.Any())
            {
                if (locations.Count == 1)
                {
                    var location = locations.First();
                    var total    = drinkQuantityNumber * drink.Price;
                    Console.WriteLine($"We can fulfill your order from {location.State}, {location.LocationName}. ");
                    Console.WriteLine($"Your total is: ${total}.  Would you like to proceed?  Y/N ");
                    string userChoice = Console.ReadLine();
                    if (userChoice == "Y" || userChoice == "y")
                    {
                        PlaceOrder(location, drinkQuantityNumber * drink.Price, drink.DrinkId, drinkQuantityNumber);
                    }
                }

                else
                {
                    int count = 1;
                    foreach (var item in locations)
                    {
                        Console.WriteLine($"{count} - Name: {item.LocationName} State: {item.State} ");
                        count++;
                    }
                    Console.WriteLine($"Multiple matches found: {locations.Count}, which location would you like to buy from?");

                    string identity    = Console.ReadLine();
                    int    identityNum = int.Parse(identity);
                    var    location    = locations.ToArray()[identityNum - 1];

                    PlaceOrder(location, drinkQuantityNumber * drink.Price, drink.DrinkId, drinkQuantityNumber);
                }
            }

            else
            {
                Console.Write("The drink you would like to order is out of stock.  Please lower your quantity or select a different beer");
            }
        }