Beispiel #1
0
        public bool SearchForAvailableReservations(string parkName)
        {
            GetThisParksCampgrounds(parkName);
            CampgroundDAL     campDAL = new CampgroundDAL(connectionString);
            List <Campground> thisParksCampgroundList = campDAL.GetThisParksCampgrounds(parkName);

            int    campgroundIndex = 0;
            string startDate       = "";
            string endDate         = "";

            campgroundIndex = CLIHelper.GetInteger("\nSelect a campground (enter 0 to cancel)  ___ ") - 1;
            if (campgroundIndex == -1)
            {
                return(false);  //returns to previous method (and menu)
            }
            else if (campgroundIndex < 0 || campgroundIndex > thisParksCampgroundList.Count - 1)
            {
                Console.WriteLine("\nSelect a valid campground from the list.");
                Console.ReadLine();
                return(true);
            }

            startDate = CLIHelper.GetString("What day do you plan to arrive?  mm/dd/yyyy ");
            if (!DateTime.TryParse(startDate, out DateTime startResult))
            {
                Console.WriteLine("\nThat is not an acceptable Date format");
                Console.ReadLine();
                return(true);
            }

            endDate = CLIHelper.GetString("What day do you plan to checkout?  mm/dd/yyyy ");
            if (!DateTime.TryParse(endDate, out DateTime endResult))
            {
                Console.WriteLine("\nThat is not an acceptable Date format");
                Console.ReadLine();
            }
            else if (endResult < startResult)
            {
                Console.WriteLine("\nThat departure date is before the Arrival Date. Try again.");
                Console.ReadLine();
                return(true);
            }

            SiteDAL     siteDAL            = new SiteDAL(connectionString);
            List <Site> availableCampsites = siteDAL.GetSitesFreeInCampground(thisParksCampgroundList[campgroundIndex].Name, startDate, endDate);

            Console.Clear();
            Console.Write("\n\nHere are the results matching your search criteria for:");
            Console.WriteLine("\n\nAvailable Camp Sites at " + parkName + " National Park, " + thisParksCampgroundList[campgroundIndex].Name + " Campground");
            Console.WriteLine("Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(15)
                              + "Utility".PadRight(10) + "Cost");

            int numOfDaysStaying = (Convert.ToDateTime(endDate) - Convert.ToDateTime(startDate)).Days;

            for (int i = 0; i < availableCampsites.Count - 1; i++)
            {
                Console.WriteLine(availableCampsites[i].SiteNumber.ToString().PadRight(10) + availableCampsites[i].MaxOccupancy.ToString().PadRight(12) +
                                  availableCampsites[i].HandicapAccessible.ToString().PadRight(15) + availableCampsites[i].MaxRVLength.ToString().PadRight(15) +
                                  availableCampsites[i].HasUtilities.ToString().PadRight(10) + (numOfDaysStaying * thisParksCampgroundList[campgroundIndex].DailyFee / 100).ToString("C2"));
            }

            ReserveSelectedCampsite(availableCampsites, startDate, endDate);

            return(false);
        }