/// <summary> /// Entry point for the park reservation cli /// </summary> /// <param name="args">Command line arguments which are currently ignored</param> static void Main(string[] args) { CLIHelper.EnableDebugInfo = true; try { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); string connectionString = configuration.GetConnectionString("npcampground"); IParkDAO parkDb = new ParkDAO(connectionString); IUserSecurityDAO userSecurityDb = new UserSecurityDAO(connectionString); UserManager userMgr = new UserManager(userSecurityDb); ParkReservationCLI cli = new ParkReservationCLI(userMgr, parkDb); cli.StartMenu(); } catch (Exception e) { CLIHelper.DisplayDebugInfo(e); } }
/// <summary> /// Park selection menu /// </summary> private void DisplayParkMenu() { var parks = _db.GetParks(); Dictionary <int, ParkItem> menu = new Dictionary <int, ParkItem>(); bool exit = false; while (!exit) { menu.Clear(); Console.Clear(); DisplayColored("Select a park for further details..."); for (int i = 1; i <= parks.Count; i++) { menu.Add(i, parks[i - 1]); Console.WriteLine($" ({i}) {parks[i - 1].Name}"); } Console.WriteLine(" (R) Reservation History"); Console.WriteLine(" (L) Logout"); Console.WriteLine(); var selection = CLIHelper.GetString(Message_EnterSelection); if (selection.ToLower() == Option_Logout) { _userMgr.LogoutUser(); exit = true; } else if (selection.ToLower() == Option_ReservationHistory) { var reservations = _db.GetReservationsForUserId(_userMgr.User.Id); DisplayReservationHistory(reservations); } else { try { var parkSel = int.Parse(selection); if (menu.ContainsKey(parkSel)) { DisplayParkDetailsMenu(menu[parkSel]); } else { throw new Exception(); } } catch (ExitToMainException) { // do nothing, this is the main menu } catch (Exception e) { CLIHelper.DisplayDebugInfo(e); DisplayInvalidSelection(); } } } }
/// <summary> /// Displays a list of campgrounds and prompts user to select one of them /// </summary> /// <param name="park">The park the campgrounds belong to</param> /// <param name="campgrounds">List of campgrounds</param> private void DisplaySearchMenu(ParkItem park, List <CampgroundItem> campgrounds) { Dictionary <int, CampgroundItem> menu = new Dictionary <int, CampgroundItem>(); decimal selectedDailyFee = 0.0M; string campgroundName = ""; bool exit = false; while (!exit) { ReservationInfo reservation = new ReservationInfo(); bool validSelection = false; while (!validSelection) { menu.Clear(); Console.Clear(); DisplayColored("Search for Campground Reservation"); Console.WriteLine(); DisplayCampgrounds(campgrounds, menu); Console.WriteLine(); var selection = CLIHelper.GetInteger("Which campground (enter 0 to cancel)?"); if (selection == 0) { exit = true; validSelection = true; } else if (menu.ContainsKey(selection)) { reservation.CampgroundId = menu[selection].Id; selectedDailyFee = menu[selection].DailyFee; campgroundName = menu[selection].Name; validSelection = true; } else { DisplayInvalidSelection(); } } if (!exit) { try { reservation = GetReservationInfo(reservation); } catch (ExitException) { exit = true; } try { DisplayCampsiteSelection(reservation, selectedDailyFee, campgroundName); throw new ExitToMainException(); } catch (NoAvailableCampsitesException) { Console.WriteLine(); Console.WriteLine("There are no campsites available that match your search criteria."); Console.WriteLine(Message_PressKeyContinue); Console.ReadKey(); } catch (ExitException) { exit = true; } catch (ExitToMainException) { throw; } catch (Exception e) { CLIHelper.DisplayDebugInfo(e); } } } }