private void requestPaymentType() // Ask for payment Type { PaymentTypeValidator repo = new PaymentTypeValidator(); ENTERTYPE: Console.Clear(); _consoleHelper.WriteHeaderToConsole("Payment Type"); string[] paymentOptions = new string[] { "Visa", "MasterCard", "Discover", "American Express" }; int counter = 1; foreach (var option in paymentOptions) { _consoleHelper.WriteLine($"{counter}. {option} "); counter++; } _consoleHelper.WriteExitCommand(); string input = _consoleHelper.WriteAndReadFromConsole("Enter Payment Type > "); bool userContinue = _consoleHelper.CheckForUserExit(input); if (userContinue) { UserContinue = false; return; } string selectedPaymentType = ""; try { if (!(input.Equals("")) && Convert.ToInt32(input) <= paymentOptions.Count()) { selectedPaymentType = paymentOptions[Convert.ToInt32(input) - 1]; } else { _consoleHelper.ErrorMessage("Invalid input, please select an option from the menu above."); goto ENTERTYPE; } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); _consoleHelper.ErrorMessage("Invalid payment type"); goto ENTERTYPE; } if (!repo.ValidatePaymentType(input)) { } payment.PaymentType = selectedPaymentType; }
public Customer CreateCustomer() { // Get/Validate New Customer's Name while (true) { CurrentCustomer(); var input = EnterName(); if (_consoleHelper.CheckForUserExit(input)) { return(null); } ; if (_customerName.ValidateName(input)) { Console.Clear(); customer.CustomerName = input; break; } else { _consoleHelper.ErrorMessage("Invalid. Please enter first and last name."); } } // Get/Validate New Customer's Address while (true) { CurrentCustomer(); var input = EnterStreetAddress(); if (_consoleHelper.CheckForUserExit(input)) { return(null); } ; if (_customerAddress.ValidateStreetAddress(input)) { Console.Clear(); customer.CustomerStreetAddress = input; break; } else { _consoleHelper.ErrorMessage("Invalid. Please enter in the following format 123 main st."); } } // Get/Validate New Customer's City while (true) { CurrentCustomer(); var input = EnterCity(); if (_consoleHelper.CheckForUserExit(input)) { return(null); } ; if (_customerCity.ValidateCity(input)) { Console.Clear(); customer.CustomerCity = input; break; } else { _consoleHelper.ErrorMessage("Invalid. City must contain at least 3 characters."); } } // Get/Validate New Customer's State while (true) { CurrentCustomer(); var input = EnterState(); if (_consoleHelper.CheckForUserExit(input)) { return(null); } ; if (_customerState.ValidateState(input)) { customer.CustomerState = input; Console.Clear(); break; } else { _consoleHelper.ErrorMessage("Invalid. State must be Abbreviated."); } } // Get/Validate New Customer's Zip while (true) { CurrentCustomer(); var input = EnterZip(); if (_consoleHelper.CheckForUserExit(input)) { return(null); } ; if (_customerZip.ValidateZip(input)) { Console.Clear(); customer.CustomerZip = input; break; } else { _consoleHelper.ErrorMessage("Invalid. Zip must be 5 numbers."); } } // Get/Validate New Customer's Phone Number while (true) { CurrentCustomer(); var input = EnterPhoneNumber(); if (_consoleHelper.CheckForUserExit(input)) { return(null); } ; if (_customerPhone.ValidatePhone(input)) { Console.Clear(); customer.CustomerPhone = input; IsComplete = true; break; } else { _consoleHelper.ErrorMessage("Invalid. Phone number must be in the format 111-111-1111."); } } // Add To Database if (IsComplete) { return(WriteToDb(customer)); } return(null); }