Example #1
0
        public decimal PromptForPayment()
        {
            _prompt.Message = "\n" +
                              "Please pay for your order using " + PaymentType.ToLower() + ". Enter the amount to pay:";

            //Get input and trim any $ symbol, the user might have specified.
            string userResponse = Prompt.CleanCurrencyInput(_prompt.GetUserInput());


            while (!decimal.TryParse(userResponse, out decimal num) || Convert.ToDecimal(userResponse) < TotalPrice) // while not a decimal value that is at least the amount requested
            {
                // Validate Payment (did they give enough money?)
                if (decimal.TryParse(userResponse, out num) && (Convert.ToDecimal(userResponse) < TotalPrice))
                {
                    _prompt.Message = "Inadequate amount received. You are " + (TotalPrice - Convert.ToDecimal(userResponse)).ToString("C") + " short. Please pay the full amount: " + TotalPrice.ToString("C");
                }
                else
                {
                    _prompt.Message = "That is not a valid numeric response. Please enter a number:";
                }

                //Get input and trim any $ symbol, the user might have specified.
                userResponse = Prompt.CleanCurrencyInput(_prompt.GetUserInput());
            }
            return(Convert.ToDecimal(userResponse));
        }
Example #2
0
        public virtual string PromptForCoffeeMenu()
        {
            // Prompt to optionally see menu
            _prompt.Message = "What can I get for you?\n" +
                              "\t'menu' - View menu and prices\n" +
                              "\t'order' - Create order\n";
            string userResponse = _prompt.GetUserInput();

            string[] expectedResponse = { "order", "menu" };
            while (!((IList)expectedResponse).Contains(userResponse))
            {
                // prompt again
                _prompt.Message = "Invalid option";
                userResponse    = _prompt.GetUserInput();
            }
            return(userResponse);
        }
Example #3
0
        public virtual string PromptForSize()
        {
            _prompt.Message = "What size would you like? (";
            foreach (var size in _priceList.SizeOptionList)
            {
                _prompt.Message = _prompt.Message + size.Size.ToLower() + "/";
            }
            _prompt.Message.Trim('/');
            _prompt.Message = _prompt.Message + ")";


            string userResponse = _prompt.GetUserInput();

            while (_priceList.SizeOptionList.Where(x => x.Size == userResponse).Count() < 1) // while not a valid size option
            {
                // prompt again
                _prompt.Message = "Invalid size.";
                userResponse    = _prompt.GetUserInput();
            }
            return(userResponse);
        }