예제 #1
0
        private void SearchForAvailableCampsites(Campground selectedCampground, DateTime?startDate, DateTime?endDate, int numberOfDaysToReserve)
        {
            // Used to get back into reservation info-getting loop if error throws us back here
            bool trigger = false;

            double totalCost = selectedCampground.DailyFee * numberOfDaysToReserve;

            Campsite_DAL site_DAL = new Campsite_DAL();

            campsites = site_DAL.GetCampsitesByCampground(selectedCampground.CampID, startDate, endDate);

            Console.WriteLine();
            Console.WriteLine("Results Matching Your Search Criteria");
            Console.WriteLine("Site No.".PadRight(15) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(20) + "Utility".PadRight(15) + "Cost of Reservation");

            if (campsites.Count == 0)
            {
                ClearCurrentConsoleLine();
                ClearCurrentConsoleLine();
                Console.WriteLine();
                Console.Clear();
                Console.WriteLine("Sorry! Looks like there are no available campsites for your date range. Please try a different campground or a new date range.");
                Thread.Sleep(2000);
                GetCampgroundsByPark();
                return;
            }

            foreach (var site in campsites)
            {
                Console.WriteLine($"{site.SiteNumber}".PadRight(15) + $"{site.MaxOccupancy}".PadRight(15) + $"{BoolChecker(site.Accessible)}".PadRight(15) + $"{RVChecker(site.MaxRVLength)}".PadRight(20) + $"{BoolChecker(site.UtilityAccess)}".PadRight(15) + $"{totalCost:c}");
            }

            while (trigger == false)
            {
                try
                {
                    trigger = true;
                    BookReservation(startDate, endDate);
                    return;
                }
                catch (Exception)
                {
                    ClearCurrentConsoleLine();
                    ClearCurrentConsoleLine();
                    Console.WriteLine("There was a problem with your information. Please try again.");
                    Thread.Sleep(1000);
                    ClearCurrentConsoleLine();
                    ClearCurrentConsoleLine();
                    trigger = false;
                }
            }
        }
        public void GetCampsites_Test()
        {
            Campground_DAL     testCampgroundDAL = new Campground_DAL();
            Campsite_DAL       testCampsiteDAL   = new Campsite_DAL();
            Park_DAL           testParkDAL       = new Park_DAL();
            Park               testPark          = testParkDAL.GetParks()[2];
            IList <Campground> testCampgrounds   = testCampgroundDAL.GetCampgroundsByPark(testPark.ParkID);
            List <Campsite>    testCampsites     = testCampsiteDAL.GetCampsitesByCampground(testCampgrounds[0].CampID, DateTime.Parse("2018-10-10"), DateTime.Parse("2018-10-12"));
            int siteCount = testCampsites.Count;

            // check the count of sites to make sure we're getting the right data
            Assert.AreEqual(1, siteCount);
        }