public static int GetSiteInteger(string message, string connectionString, int selectedCampgroundId, DateTime desiredStartDate, DateTime desiredEndDate) { string userInput = String.Empty; int intValue = 0; int numberOfAttempts = 0; SiteSqlDAL siteDal = new SiteSqlDAL(connectionString); List <Site> sitesForSelectedCampground = siteDal.GetListOfTop5AvailableSitesAtCampground(selectedCampgroundId, desiredStartDate, desiredEndDate); List <int> availableSiteIds = new List <int>(); foreach (Site site in sitesForSelectedCampground) { availableSiteIds.Add(site.Site_Id); } do { if (numberOfAttempts > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" Invalid input. Please try again\n"); Console.ForegroundColor = ConsoleColor.White; } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write(message); Console.ForegroundColor = ConsoleColor.White; userInput = Console.ReadLine(); numberOfAttempts++; Console.WriteLine(); }while (!int.TryParse(userInput, out intValue) || (!availableSiteIds.Contains(intValue))); return(intValue); }
private void PrintAvailableSitesList() { int desiredNumberOfDays = (desiredEndDate.Date - desiredStartDate.Date).Days + 1; SiteSqlDAL siteDal = new SiteSqlDAL(connectionString); List <Site> sites = siteDal.GetListOfTop5AvailableSitesAtCampground(selectedCampgroundId, desiredStartDate, desiredEndDate); if (sites.Count == 0) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(" There are NO campsites available on your desired dates. Would you like to:\n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" 1 - Select a new park"); Console.WriteLine(" 2 - Enter new search criteria"); Console.WriteLine(" 3 - Return to the Main Menu\n"); int noSitesChoice = CLIHelper.GetSubMenuInteger(" Selection: "); if (noSitesChoice == 1) { Console.Clear(); PrintParkList(); SelectAPark(); Console.Clear(); PrintCampgroundList(); PromptForSiteSearchCriteria(); Console.Clear(); PrintAvailableSitesList(); } else if (noSitesChoice == 2) { Console.Clear(); PrintCampgroundList(); PromptForSiteSearchCriteria(); Console.Clear(); PrintAvailableSitesList(); } } else { CampgroundSqlDAL campgroundDal = new CampgroundSqlDAL(connectionString); Campground selectedCampground = campgroundDal.GetSelectedCampground(selectedCampgroundId); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($" Campsites available at {selectedCampground.Name} \n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" Site No.".PadRight(15) + "Max Occup.".PadRight(14) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(17) + "Utility".PadRight(11) + "Cost ".PadLeft(9)); foreach (Site site in sites) { string accessibleYesOrNo = ""; string maxRVLengthNumOrNA = ""; string utilitiesYesOrNA = ""; if (site.Accessible) { accessibleYesOrNo = "Yes"; } else { accessibleYesOrNo = "No"; } if (site.Max_RV_Length == 0) { maxRVLengthNumOrNA = "N/A"; } else { maxRVLengthNumOrNA = site.Max_RV_Length.ToString(); } if (site.Utilities) { utilitiesYesOrNA = "Yes"; } else { utilitiesYesOrNA = "N/A"; } Console.WriteLine(" " + site.Site_Id.ToString().PadRight(9) + " " + site.Max_Occupancy.ToString().PadRight(10) + " " + accessibleYesOrNo.PadRight(11) + " " + maxRVLengthNumOrNA.PadRight(13) + " " + utilitiesYesOrNA.PadRight(9) + ("$" + Math.Round((desiredNumberOfDays * selectedCampground.Daily_Fee), 2)).PadLeft(9)); } } Console.WriteLine(); }