public static IReadOnlyList <Package> GetStartupPackageList() { //Double Checked, Thread Safe Singleton returns if (_packageList == null) { lock (SyncLock) { if (_packageList == null) { _packageList = new PackageList(); } } } return(_packageList._startupPackageList); }
public override bool Execute() { while (true) { IReadOnlyList <Package> startupList = PackageList.GetStartupPackageList(); if (_contextTrip._reservations.Count > 0) { Console.WriteLine($"There are {_contextTrip._reservations.Count} packages reserved on this trip:"); } Console.WriteLine($"Enter the number next to a package to select it for reservation."); Console.WriteLine($"Type [done] to continue or type [later] to save and return later."); for (var package = 0; package < startupList.Count; package++) { Console.WriteLine($"{package + 1}. {startupList[package]._transport} from {startupList[package]._origin} to {startupList[package]._destination}. Travel Time = {startupList[package]._hoursOfTravelTime.ToString()}"); } string input1 = Console.ReadLine(); Console.WriteLine(); if (!string.IsNullOrWhiteSpace(input1)) { if (input1.Equals("done", StringComparison.CurrentCultureIgnoreCase)) { //this if statement prevents continuing with no travelers if (_contextTrip._reservations.Count > 0) { _contextTrip._stateType = TripStateType.ChoosePayment; _contextTrip._state = TripStateFactory.Make(_contextTrip); return(true); } else { Console.WriteLine("Please reserve at least one package to continue Trip creation."); return(true); } } else if ((input1.Equals("later", StringComparison.CurrentCultureIgnoreCase))) { //Save() return(false); break; } } else { Console.WriteLine("Blank not accepted."); return(true); } int output; if (int.TryParse(input1, out output) && (output > 0 && output <= startupList.Count)) { Console.WriteLine($"Enter departure time in mm/dd/yy hh:mm format"); string departure = Console.ReadLine(); Console.WriteLine(); DateTime departureDateTime; if (DateTime.TryParse(departure, out departureDateTime)) { Reservation newReservation = new Reservation(departureDateTime, startupList[output - 1]); _contextTrip.AddReservation(newReservation); return(true); } else { Console.WriteLine("Please enter a valid date/time to reserve package for Trip."); return(true); } } else { Console.WriteLine($"Please enter a valid integer"); return(true); } } }