Example #1
0
        private void PurchaseMenu()
        {
            bool isTransactionFinished = false;

            while (!isTransactionFinished)
            {
                Console.WriteLine($"\n{machineTopAndBottom}");
                Console.WriteLine($"Balance: {vm.Balance,0:C}");
                string selection = (string)ui.PromptForSelection(PURCHASE_MENU_OPTIONS);
                if (selection == PURCHASE_MENU_OPTION_UPDATEBALANCE)
                {
                    Console.WriteLine($"{selection}");

                    string[] wholeDollarAmount = { "1", "2", "5", "10", "20" };

                    object depositCheck = null;
                    while (depositCheck == null)
                    {
                        depositCheck = ui.GetChoiceFromUserInput(wholeDollarAmount);//GetChoiceFromUserInput will make sure amount is valid
                    }

                    int deposit = int.Parse(depositCheck.ToString());
                    vm.DepositFunds(deposit);
                }
                else if (selection == PURCHASE_MENU_ITEM)
                {
                    if (vm.Balance == 0)
                    {
                        Console.WriteLine("please deposit funds using menu option 1");
                        isTransactionFinished = false;
                    }
                    else
                    {
                        Console.WriteLine($"{selection} or enter 0 to cancel");

                        object validSlotCheck = "";
                        while (validSlotCheck == null || (object)validSlotCheck == "")
                        {
                            validSlotCheck = ui.GetChoiceFromUserInput(ARRAY_OF_SLOTS);//GetChoiceFromUserInput will make sure product slot selected is valid
                        }

                        if (validSlotCheck.ToString() == "0")
                        {
                            isTransactionFinished = false;
                        }
                        else
                        {
                            string input = validSlotCheck.ToString().ToUpper();

                            Console.WriteLine(vm.PurchaseProduct(input));
                        }
                    }
                }
                else if (selection == PURCHASE_MENU_OPTION_FINISH_TRANSACTION)
                {
                    isTransactionFinished = vm.FinishTransaction(machineTopAndBottom);
                }
            }
        }