Esempio n. 1
0
        public void SearchAvailableReservation(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Console.WriteLine($"{park.Name} National Park");
                Console.WriteLine($"| {"Campground ID".PadRight(15)} | " +
                                  $"| {"Campground Name".PadRight(35)} | " +
                                  $"| {"Month Open".PadRight(10)} | " +
                                  $"| {"Closing Month".PadRight(15)} | " +
                                  $"| {"Daily Fee".PadRight(10)} | ");
                Console.WriteLine(new string('-', 100));

                Dictionary <int, Campground> CampgroundDictionary = _park.GetCampgroundDictionary(park);
                foreach (KeyValuePair <int, Campground> item in CampgroundDictionary)
                {
                    Console.WriteLine($"| {item.Value.CampgroundID.ToString().PadRight(15)} | " +
                                      $"| {item.Value.CampgroundName.PadRight(35)} | " +
                                      $"| {item.Value.DisplayMonthOpen.ToString().PadRight(10)} | " +
                                      $"| {item.Value.DisplayMonthClose.ToString().PadRight(15)} | " +
                                      $"| {item.Value.DailyFee.ToString("C").PadRight(10)} |");
                }
                Console.WriteLine("Which campground (enter 0 to cancel)? __");
                var selection = Console.ReadKey().KeyChar.ToString();
                if (selection == "0")
                {
                    Console.Clear();
                    return;
                }
                try
                {
                    int sel = int.Parse(selection);


                    if (CampgroundDictionary.ContainsKey(sel))
                    {
                        Console.WriteLine(") What is the arrival date? Enter date as: yyyy-mm-dd:");
                        string   arrival = Console.ReadLine().ToString();
                        DateTime arr     = DateTime.Parse(arrival);

                        Console.WriteLine("What is the departure date? Enter date as: yyyy-mm-dd:");
                        string   departure = Console.ReadLine().ToString();
                        DateTime dep       = DateTime.Parse(departure);
                        if (arr >= DateTime.Now && dep >= DateTime.Now)
                        {
                            ViewAllSelectedSites(CampgroundDictionary[sel], arrival, departure);
                        }
                        else
                        {
                            Console.WriteLine("Please enter future dates");
                            Console.ReadKey();
                            Console.Clear();
                        }
                    }
                    else
                    {
                        Console.WriteLine(") Please only enter a valid campground number");
                        Console.ReadKey();
                        Console.Clear();
                    }
                }
                catch
                {
                    Console.WriteLine(") Please only enter a valid campground and dates");
                    Console.ReadKey();
                    Console.Clear();
                }
            }
        }
Esempio n. 2
0
        public void SearchAvailableReservation(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Console.WriteLine($"{park.Name} National Park");
                Console.WriteLine($"| {"Campground ID".PadRight(15)} | " +
                                  $"| {"Campground Name".PadRight(35)} | " +
                                  $"| {"Month Open".PadRight(10)} | " +
                                  $"| {"Closing Month".PadRight(15)} | " +
                                  $"| {"Daily Fee".PadRight(10)} | ");
                Console.WriteLine(new string('-', 100));

                Dictionary <int, Campground> CampgroundDictionary = _park.GetCampgroundDictionary(park);
                foreach (KeyValuePair <int, Campground> item in CampgroundDictionary)
                {
                    Console.WriteLine($"| {item.Value.CampgroundID.ToString().PadRight(15)} | " +
                                      $"| {item.Value.CampgroundName.PadRight(35)} | " +
                                      $"| {item.Value.DisplayMonthOpen.ToString().PadRight(10)} | " +
                                      $"| {item.Value.DisplayMonthClose.ToString().PadRight(15)} | " +
                                      $"| {item.Value.DailyFee.ToString("C").PadRight(10)} |");
                }
                int sel = NationalPark.GetInteger("Which campground would you like to search for an available reservation? (enter 0 to cancel)?");
                if (sel == 0)
                {
                    exit = true;
                }
                try
                {
                    if (CampgroundDictionary.ContainsKey(sel))
                    {
                        Console.WriteLine("What is the arrival date? Enter date as: yyyy-mm-dd:");
                        string   arrival = Console.ReadLine().ToString();
                        DateTime arr     = DateTime.Parse(arrival);

                        Console.WriteLine("What is the departure date? Enter date as: yyyy-mm-dd:");
                        string   departure = Console.ReadLine().ToString();
                        DateTime dep       = DateTime.Parse(departure);

                        _park.ValidateReservationDates(dep, arr);
                        ViewAllSelectedSites(CampgroundDictionary[sel], arrival, departure);
                    }
                    else
                    {
                        Console.WriteLine("Please only enter a valid campground number");
                        Console.ReadKey();
                    }
                }
                catch (InvalidArrivalDateException)
                {
                    Console.WriteLine("Please only enter future dates.");
                    Console.ReadKey();
                }
                catch (InvalidDepartureDateException)
                {
                    Console.WriteLine("Please only enter and end date that is after your arrival date.");
                    Console.ReadKey();
                }
                catch (Exception)
                {
                    Console.WriteLine(") Please only enter a valid campground number");
                    Console.ReadKey();
                }
            }
        }