/// <summary>
        /// Submenu prompts user to enter dates to search for sites available for reservation
        /// </summary>
        /// <param name="park">The current selected park</param>
        private void ReservationScreen(Park park)
        {
            bool exit = false;

            while (!exit)
            {
                var campgroundList   = dal.GetCampgroundList(park);
                int campgroundChoice = GetInteger("Which campground (enter 0 to cancel)? ");
                if (campgroundChoice == 0)
                {
                    exit = true;
                }
                else
                {
                    try
                    {
                        //Console.Clear();
                        //CampGroundMenu(park);
                        var         campground = campgroundList[campgroundChoice - 1];
                        List <Site> availableSites;

                        Console.WriteLine("What is the arrival date? MM/DD/YYYY");
                        DateTime arrival = Convert.ToDateTime(Console.ReadLine());

                        Console.WriteLine("What is the departure date? MM/DD/YYYY");
                        DateTime departure = Convert.ToDateTime(Console.ReadLine());

                        // Logic check on user date entry.
                        if (arrival >= departure)
                        {
                            throw new Exception("Please enter a valid date range. Arrival date should be before departure.");
                        }
                        else if (arrival < DateTime.Now)
                        {
                            throw new Exception("Please enter a valid date. Arrival date must be after today's date.");
                        }

                        availableSites = dal.SearchAvailableReservations(campground, arrival, departure);
                        decimal dailyFee = campground.DailyFee;

                        ChooseSite(availableSites, arrival, departure, dailyFee);
                        return;
                    }
                    catch (FormatException) // Only caught if date is entered in an invalid format
                    {
                        Console.WriteLine("Please Enter Date in MM/DD/YYYY Format.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
Exemple #2
0
        public void SearchAvailableReservationsTest()
        {
            // The only reservation in the list is from 10/21/2019 to 10/25/2019
            // Any other date range should display one available site (the only site in the DB)
            DateTime StartDate = new DateTime(2019, 11, 1);
            DateTime EndDate   = new DateTime(2019, 11, 5);

            var park       = dal.GetParkList()[0];
            var campground = dal.GetCampgroundList(park)[0];

            var list = dal.SearchAvailableReservations(campground, StartDate, EndDate);

            Assert.AreEqual(1, list.Count);
        }