Esempio n. 1
0
        /// <summary>
        /// Displays available campsites within a campground based on the user's selection and options
        /// </summary>
        /// <param name="campId"></param>
        /// <param name="arriveDate"></param>
        /// <param name="departDate"></param>
        public void DisplayAvailableSites(int campId, DateTime arriveDate, DateTime departDate)
        {
            SiteSqlDAL  siteDal    = new SiteSqlDAL(DatabaseConnection);
            List <Site> sites      = siteDal.GetCampgroundSites(campId, arriveDate, departDate);
            bool        timeToExit = false;

            while (!timeToExit)
            {
                if (sites.Count == 0)
                {
                    Console.WriteLine("There are no available sites on that date, try again.");
                    Console.ReadKey();
                    Console.Clear();
                    Header();
                    timeToExit = true;
                    //CampgroundReservation(_parks[campId]);
                }
                else
                {
                    int numDays = (int)(departDate - arriveDate).TotalDays + 1;

                    decimal totalCost = _campgrounds[campId - 1].CalculateCost(_campgrounds[campId - 1], numDays);

                    Console.Clear();
                    Header();
                    Console.WriteLine("Results Matching Your Search Criteria");
                    Console.WriteLine();
                    Console.WriteLine($"{siteNo,6} | {maxOcc,9} | {access,9} | {rvLngth,9} | {utility,9} | {cost,9}");
                    for (int i = 0; i < sites.Count; i++)
                    {
                        Console.WriteLine($"{sites[i].SiteNumber,8} | {sites[i].MaxOccupancy,10} | {sites[i].Accessible,11} | {sites[i].MaxRvLength,13} | {sites[i].Utilities,9} | {totalCost.ToString("c"),9}");
                    }  //iterates through the Sites List to display to user

                    Console.WriteLine();
                    int siteId = CLIHelper.GetInteger("Which site would you like to reserve ? (enter 0 to cancel)");
                    if (siteId == 0)
                    {
                        Console.Clear();
                        Header();
                        timeToExit = true;
                    }

                    Console.WriteLine();
                    string resName = CLIHelper.GetString("What name should your reservation be called?");

                    ReservationSqlDAL sqlDal = new ReservationSqlDAL(DatabaseConnection);

                    int resConfirmationId = sqlDal.BookReservation(siteId, arriveDate, departDate, resName);

                    Console.WriteLine();
                    Console.WriteLine($"The reservation has been made and your confirmation number is {resConfirmationId}");
                    Console.WriteLine("Click any key to exit the program.");

                    timeToExit = true;

                    Console.ReadKey();
                }
            }
        }