public static IReadOnlyList <Person> GetStartupPersonList() { //Double Checked, Thread Safe Singleton returns if (_personList == null) { lock (SyncLock) { if (_personList == null) { _personList = new PersonList(); } } } return(_personList._startupPersonList); }
public Payment(Trip context) { _trip = context; bool success = false; while (success == false) { Console.WriteLine($"Enter the integer next to a person from the list to select who pays the bill"); IReadOnlyList <Person> startupList = PersonList.GetStartupPersonList(); for (var person = 0; person < startupList.Count; person++) { Console.WriteLine($"{person + 1}. {startupList[person]._name}, {startupList[person]._phoneNum}\n"); } string input = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(input)) { int output; if (int.TryParse(input, out output) && (output > 0 && output <= startupList.Count)) { PaidBy = (startupList[output - 1]); Console.WriteLine($"{startupList[output-1]._name} selected to pay bill."); success = true; break; } else { Console.WriteLine("Please enter a valid integer."); success = false; } } else { Console.WriteLine("Blank not accepted."); success = true; } } }
public override bool Execute() { while (true) { if (_contextTrip._travelers.Count > 0) { Console.WriteLine($"There are currently {_contextTrip._travelers.Count} travelers booked on this trip."); for (var traveler = 0; traveler < _contextTrip._travelers.Count; traveler++) { Console.WriteLine($"{traveler + 1}. {_contextTrip._travelers[traveler]._name}"); } Console.WriteLine(); } Console.WriteLine($"Type an integer corresponding to the listed position of a person to add as a traveler to Trip #{_contextTrip._ID}"); Console.WriteLine($"Type [done] when you have entered all travelers, type [later] to save and return later\n"); //outputs contents of the Read-Only list IReadOnlyList <Person> startupList = PersonList.GetStartupPersonList(); for (var person = 0; person < startupList.Count; person++) { Console.WriteLine($"{person + 1}. {startupList[person]._name}, {startupList[person]._phoneNum}"); } string input = Console.ReadLine(); Console.WriteLine(); if (!string.IsNullOrWhiteSpace(input)) { if (input.Equals("done", StringComparison.CurrentCultureIgnoreCase)) { //this if statement prevents continuing with no travelers if (_contextTrip._travelers.Count > 0) { _contextTrip._stateType = TripStateType.AddPackages; _contextTrip._state = TripStateFactory.Make(_contextTrip); return(true); } else { Console.WriteLine("Please enter at least one traveler to continue Trip creation."); return(true); } } else if (input.Equals("later", StringComparison.CurrentCultureIgnoreCase)) { //Save() return(false); } } else { Console.WriteLine("Blank not accepted - enter [done] to move to next"); } int output; if (int.TryParse(input, out output) && (output > 0 && output <= startupList.Count) && !_contextTrip._travelers.Contains(startupList[output - 1])) { _contextTrip.AddTraveler(startupList[output - 1]); Console.WriteLine($"{startupList[output-1]._name} successfully added to trip."); return(true); } else { Console.WriteLine("Please enter a valid integer corresponding to a person not yet included as a traveler"); return(true); } } }