/// <summary> /// The override of ExecuteSelection handles whatever selection was made by the user. /// This is where any business logic is executed. /// </summary> /// <param name="choice">"Key" of the user's menu selection</param> /// <returns></returns> protected override bool ExecuteSelection(string choice) { switch (choice) { case "1": // Do whatever option 1 is int campgroundChoice = CLIMenu.GetInteger($"Which Campground?"); if (campgroundChoice > 0 && campgroundChoice <= park.Campgrounds.Count) { Campground campground = park.Campgrounds[campgroundChoice - 1]; campground.Sites = siteDao.GetSiteId(campground.CampgroundId); string arrivalDate = CLIMenu.GetString("What is your arrival date? (yyyy-mm-dd)"); string departureDate = CLIMenu.GetString("What is your departure date?(yyyy-mm-dd)"); SiteMenu siteMenu = new SiteMenu(park, campground, siteDao, reservationDao, arrivalDate, departureDate); siteMenu.Run(); } else { Console.WriteLine("That campsite is not in our database."); } Pause(""); return(true); case "2": // Do whatever option 2 is WriteError("When this option is complete, we will exit this submenu by returning false from the ExecuteSelection method."); Pause(""); return(false); } return(true); }
/// <summary> /// The override of ExecuteSelection handles whatever selection was made by the user. /// This is where any business logic is executed. /// </summary> /// <param name="choice">"Key" of the user's menu selection</param> /// <returns></returns> protected override bool ExecuteSelection(string choice) { switch (choice) { case "1": // Do whatever option 1 is int userSelection = CLIMenu.GetInteger("Please Make a reservation"); string userName = CLIMenu.GetString("What is Your Name?"); foreach (Site site in sites) { if (userSelection == site.SiteNumber) { int resId = reservationDao.AddReservation(site.SiteId, userName, site.UserStartTime, site.UserEndTime); Console.WriteLine($"Reservation Confirmed! Your reservation number is {resId}!"); Pause(""); return(true); } } Console.WriteLine("Incorrect Site Number Try again."); Pause(""); return(true); case "2": // Do whatever option 2 is WriteError("When this option is complete, we will exit this submenu by returning false from the ExecuteSelection method."); Pause(""); return(false); } return(true); }
/// <summary> /// The override of ExecuteSelection handles whatever selection was made by the user. /// This is where any business logic is executed. /// </summary> /// <param name="choice">"Key" of the user's menu selection</param> /// <returns></returns> //protected override bool ExecuteSelection(string choice) //{ // switch (choice) // { // case "1": // Go to new SubMenu for Reservations // //WriteError("Not yet implemented"); // //ReservationsMenu rm = new ReservationsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); // //rm.Run(); // //Pause(""); // return true; // } // return true; //} #region Original SearchForAvailableReservations - No longer using //private void SearchForAvailableReservations() //{ // IList<Campground> campgrounds = campgroundDAO.GetCampgroundsByParkId(selectedPark.ParkId); // string pickCampground = CLIMenu.GetString("Which campground would you like (enter 0 to cancel)?"); // if (pickCampground == "0") // { // CampgroundsMenu cm = new CampgroundsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); // cm.Run(); // Pause(""); // } // else if ((Convert.ToInt32(pickCampground)) > campgrounds.Count) // { // Console.WriteLine("Please choose a valid campground"); // Pause(""); // ReservationsMenu rm = new ReservationsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); // rm.Run(); // Pause(""); // } // //pulled out of else statement as not needed removed as not needed // string arrivalDate = CLIMenu.GetDateTime("What is the arrival date?"); // DateTime.TryParse(arrivalDate, out DateTime arrival); // Adding in a parse for arrival date to make sure that the arrival date is before the departure date // string departureDate = CLIMenu.GetDateTime("What is the departure date?"); // DateTime.TryParse(departureDate, out DateTime departure);// Adding in a parse for departure date to make sure that the arrival date is before the departure date // if (arrival > departure) // { // Console.WriteLine("Your departure date cannot be before your arrival date. Please try again with a valid date of departure."); // Pause(""); // ReservationsMenu rm = new ReservationsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); // rm.Run(); // Pause(""); // } // IList<Site> sites = siteDAO.ViewAvailableReservations(pickCampground, arrivalDate, departureDate); // if (sites.Count > 0) // { // decimal campgroundCost = campgroundDAO.GetCampgroundCost(pickCampground); // Console.WriteLine("Results Matching Your Search Criteria"); // Console.WriteLine($"{"Site No.",-10} {"Max Occupancy",10} {"Accessible?",14} {"Max RV Length",18} {"Utility",11} {"Cost",6}"); // foreach (Site site in sites) // { // Console.WriteLine($"{site.SiteId,-10} {site.MaxOccupancy,-16} {site.Accessible.ToYesNo(),-16} {site.MaxRVLength.ToLengthNA(),-17} {site.Utilities.ToYesNA(),-9} {campgroundCost.ToString("C"),0}"); // } // Console.WriteLine(); // string siteToReserve = CLIMenu.GetString("Which site should be reserved (enter 0 to cancel)"); // if (siteToReserve == "0") // { // ReservationsMenu rm = new ReservationsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); // rm.Run(); // Pause(""); // } // //else if ((Convert.ToInt32(siteToReserve)) > sites.Count) // //{ // // Console.WriteLine("Please choose a valid site"); // // Pause(""); // //} // bool siteExistsInList = false; // foreach (Site site in sites) // { // if (site.SiteId.ToString() == siteToReserve) // { // siteExistsInList = true; // } // } // if (!siteExistsInList) // { // Console.WriteLine("We're sorry, that Site ID is not in our list. Please try again."); // return; // } // string name = CLIMenu.GetString("What name should the reservation be made under?"); // MakeReservation(siteToReserve, name, arrivalDate, departureDate); // } // else // { // Console.WriteLine("We're sorry, there are no campsites available. Please try again with different dates."); // return; // } //} #endregion private void SearchForAvailableReservations() { IList <Campground> campgrounds = campgroundDAO.GetCampgroundsByParkId(selectedPark.ParkId); string pickCampground = CLIMenu.GetString("Which campground would you like (enter 0 to cancel)?"); if (pickCampground == "0") { CampgroundsMenu cm = new CampgroundsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); cm.Run(); Pause(""); } else if ((Convert.ToInt32(pickCampground)) > campgrounds.Count) { Console.WriteLine("Please choose a valid campground"); Pause(""); ReservationsMenu rm = new ReservationsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); rm.Run(); Pause(""); } while (true) { // Putting into a while statement to re-prompt user for input when inputting invalid information string arrivalDate = CLIMenu.GetDateTime("What is the arrival date? (DD/MM/YYYY)"); string departureDate = CLIMenu.GetDateTime("What is the departure date? (DD/MM/YYYY)"); while (true) { DateTime.TryParse(arrivalDate, out DateTime arrival); // Adding in a parse for arrival date to make sure that the arrival date is before the departure date DateTime.TryParse(departureDate, out DateTime departure); // Adding in a parse for departure date to make sure that the arrival date is before the departure date if (arrival > departure) // check to make sure that the arrival date is before the departure date { Console.WriteLine("Your departure date cannot be before your arrival date. Please try again with a valid date of departure."); break; } IList <Site> sites = siteDAO.ViewAvailableReservations(pickCampground, arrivalDate, departureDate); if (sites.Count > 0) { decimal campgroundCost = campgroundDAO.GetCampgroundCost(pickCampground); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine($"{"Site No.",-10} {"Max Occupancy",10} {"Accessible?",14} {"Max RV Length",18} {"Utility",11} {"Cost",6}"); foreach (Site site in sites) { Console.WriteLine($"{site.SiteNumber,-10} {site.MaxOccupancy,-16} {site.Accessible.ToYesNo(),-16} {site.MaxRVLength.ToLengthNA(),-17} {site.Utilities.ToYesNA(),-9} {campgroundCost.ToString("C"),0}"); } Console.WriteLine(); } else { Console.WriteLine("We're sorry, there are no campsites available. Please try again with different dates."); break; } string siteToReserve = CLIMenu.GetString("Which site should be reserved (enter 0 to cancel)"); while (true) { #region Site to reserve area if (siteToReserve == "0") { ReservationsMenu rm = new ReservationsMenu(selectedPark, campgroundDAO, parkDAO, reservationDAO, siteDAO); rm.Run(); Pause(""); } else if (siteToReserve != "0") { foreach (Site site in sites) { if (site.SiteNumber == Convert.ToInt32(siteToReserve)) { string name = CLIMenu.GetString("What name should the reservation be made under?"); MakeReservation(siteToReserve, name, arrivalDate, departureDate); break; } } Console.WriteLine("We're sorry, that Site number is not in our list. Please try again."); Pause(""); Console.Clear(); // Clear the menu as to not clutter the experience for the user // Add in the BeforeDisplayMenu, Arrival Date & Departure Date from user with the original message BeforeDisplayMenu(); Console.WriteLine($"What is the arrival date? (DD/MM/YYYY) {arrivalDate}"); Console.WriteLine($"What is the departure date? (DD/MM/YYYY) {departureDate}"); break; } #endregion } } } }