public static int GetCampgroundInteger(string message, string connectionString, int selectedParkId) { string userInput = String.Empty; int intValue = 0; int numberOfAttempts = 0; CampgroundSqlDAL campgroundDal = new CampgroundSqlDAL(connectionString); List <Campground> campgroundsForSelectedPark = campgroundDal.GetListOfCampgrounds(selectedParkId); do { if (numberOfAttempts > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" Invalid input format. 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) || intValue > campgroundsForSelectedPark.Count); return(intValue); }
private void PrintCampgroundList() { CampgroundSqlDAL campgroundDal = new CampgroundSqlDAL(connectionString); List <Campground> campgrounds = campgroundDal.GetListOfCampgrounds(selectedParkId); ParkSqlDAL parkDal = new ParkSqlDAL(connectionString); List <Park> parksById = parkDal.GetAllParksById(); DateTimeFormatInfo monthName = new DateTimeFormatInfo(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"CAMPGROUNDS AT {parksById[selectedParkId - 1].Name} PARK\n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" ID".PadRight(6) + "- " + "Name".PadRight(33) + "Open".PadRight(15) + "Close".PadRight(15) + "Daily Fee".PadLeft(10)); for (int i = 0; i < campgrounds.Count; i++) { Console.WriteLine(" " + campgrounds[i].Campground_Id.ToString().PadRight(3) + "- " + campgrounds[i].Name.PadRight(33) + monthName.GetMonthName((campgrounds[i].Open_From_MM)).ToString().PadRight(15) + monthName.GetMonthName((campgrounds[i].Open_To_MM)).ToString().PadRight(15) + ("$" + Math.Round(campgrounds[i].Daily_Fee, 2)).PadLeft(10)); } Console.WriteLine(); }