/// <summary> /// The method where we will choose the correct option to go /// </summary> public void Show() { int option; const int EXIT = 0, EXPENSE = 1, EXPENSE_TYPE = 2, PAYMENT_METHOD = 3, INCOME_TYPE = 4, INCOME = 5, BALANCE = 6; do { Menu(); Console.WriteLine("Choose an option."); if (int.TryParse(Console.ReadLine(), out option)) { switch (option) { case EXPENSE: ExpenseUI expUI = new ExpenseUI(); expUI.Show(); break; case EXPENSE_TYPE: ExpenseTypeUI retUI = new ExpenseTypeUI(); retUI.Show(); break; case PAYMENT_METHOD: PaymentMethodUI metUI = new PaymentMethodUI(); metUI.Show(); break; case INCOME_TYPE: IncomeTypeUI incTUI = new IncomeTypeUI(); incTUI.Show(); break; case INCOME: IncomeUI incUI = new IncomeUI(); incUI.Show(); break; case BALANCE: BalanceUI balUI = new BalanceUI(); balUI.Show(); break; case EXIT: Console.WriteLine("Bye! Bye!"); break; default: Console.WriteLine("Unknown option\nPlease try again!"); break; } } else { option = 999; } } while (option != 0); }
/// <summary> /// The method that will choose a payment method in the repository /// </summary> /// <returns>A payment method</returns> private PaymentMethod GetPaymentMethod() { PaymentMethod method = null; ExpenseController ec = new ExpenseController(); PaymentMethodUI pmUI = new PaymentMethodUI(); int numPayMeth = ec.GetPaymentMethodRepositorySize(); if (numPayMeth == 0) { Console.WriteLine("Create a new Payment Method"); pmUI.ShowRegisterPayment(); method = ec.GetLastPaymentMethod(); } else { int option = 999; Console.WriteLine("Choose a Payment Method"); pmUI.List(); do { if (int.TryParse(Console.ReadLine(), out option)) { method = ec.GetPaymentMethod(option); } else { option = -1; } } while (option < 0 || option > numPayMeth); } return method; }