private void GetCampgroundAvailability(Dictionary <int, Campground> campgrounds)
        {
            CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL();
            int  campground       = CLIHelper.GetInteger("Which Campground (enter 0 to cancel):");
            bool returnToPrevious = campground == int.Parse(command_Cancel);

            //Return to previous screen if user enters 0
            if (returnToPrevious)
            {
                return;
            }

            while (!campgrounds.ContainsKey(campground))
            {
                campground = campground = CLIHelper.GetInteger("Invalid choice. Please pick a campground Site number from available list:");
            }
            ;

            bool stillBooking = false;

            do
            {
                DateTime startDate = CLIHelper.GetDateTime("Enter start date (YYYY/MM/DD):");
                DateTime endDate   = CLIHelper.GetDateTime("Enter end date (YYYY/MM/DD):");

                var availableSites = campgroundDAL.GetCampgroundAvailability(campgrounds[campground].Name, startDate, endDate);

                if (availableSites.Count > 0)
                {
                    List <int> availableSiteNumbers = new List <int>();

                    int totalReservDays = (int)(endDate - startDate).TotalDays;

                    Console.Clear();
                    Console.WriteLine("Results Matching Your Search Criteria");
                    Console.WriteLine(String.Format("").PadRight(30, '='));
                    Console.WriteLine("{0,3}{1,12}{2,13}{3,14}{4,9}{5,10}{6,7}", "Campground", "Site No.", "Max Occup.", "Accessible?", "RV Len", "Utility", "Cost");
                    foreach (var site in availableSites)
                    {
                        double cost = campgrounds[campground].Daily_Fee * totalReservDays;
                        availableSiteNumbers.Add(site.SiteNumber);

                        Console.WriteLine(campgrounds[campground].Name.PadRight(17) + site.SiteNumber.ToString().PadRight(12) + site.MaxOccupancy.ToString().PadRight(13) +
                                          site.WheelchairAccess.PadRight(11) + site.MaxRVLength.PadRight(10) + site.UtilityHookups.PadRight(9) + cost);
                    }

                    bool reservationSuccessful = BookReservation(availableSiteNumbers, startDate, endDate);
                    if (reservationSuccessful)
                    {
                        stillBooking = false;
                    }
                }
                else
                {
                    Console.WriteLine("Sorry, there are no sites available in the specified date range.");
                    stillBooking = CLIHelper.GetBoolFromYesOrNo("Would you like to enter another date range?");
                }
            } while (stillBooking);
        }
Beispiel #2
0
        public void GetCampgroundAvailabilityTest()
        {
            //Arrange
            CampgroundSqlDAL campgroundSqlDAL = new CampgroundSqlDAL();
            DateTime         dt1 = new DateTime(2018, 3, 3, 0, 0, 0);
            DateTime         dt2 = new DateTime(2018, 3, 5, 0, 0, 0);

            //Act
            List <Site> sites = campgroundSqlDAL.GetCampgroundAvailability("Blackwoods", dt1, dt2);

            //Assert
            Assert.AreEqual(5, sites.Count);
        }