Esempio n. 1
0
        public void SearchReservation(int parkId, string commandOption)
        {
            if (commandOption == "1")
            {
                Console.WriteLine("Which campground (enter 0 to cancel)?__");
                Console.WriteLine();
            }
            else if (commandOption == "2")
            {
                Console.WriteLine("Would you like to make a reservation in this park? (any number for yes and [0] for no)?__");
                Console.WriteLine();
            }
            int inputId = int.Parse(Console.ReadLine());

            if (inputId == 0)
            {
                Console.Clear();
                ViewParks();
                Console.WriteLine();
            }
            else if (inputId != 0)
            {
                Console.WriteLine("What is the arrival date? __/__/____");
                Console.WriteLine();
                DateTime fromDate = Convert.ToDateTime(Console.ReadLine());
                Console.WriteLine();
                Console.WriteLine("What is the departure date? __/__/____");
                Console.WriteLine();
                string   stringDate = Console.ReadLine();
                DateTime toDate     = Convert.ToDateTime(stringDate);

                SiteSqlDAL  newAvailSites = new SiteSqlDAL(connectionString);
                List <Site> sites         = new List <Site>();

                if (commandOption == "2")
                {
                    sites = newAvailSites.GetAvailableSitesFromPark(toDate, fromDate, parkId);
                }
                else if (commandOption == "1")
                {
                    sites = newAvailSites.GetAvailableSites(toDate, fromDate, inputId);
                }

                if (sites.Count == 0)
                {
                    Console.Clear();
                    Console.WriteLine("there are no sites available. please enter an alternative date range");
                    SearchReservation(parkId, commandOption);
                }
                else
                {
                    Console.WriteLine("{0, -20}{1, -20}{2, -20}{3, -20}{4, -20}{5, -20}", "Site Id", "Max Occup.", "Accessible", "Max RV Length", "Utility", "Cost");
                    foreach (Site site in sites)
                    {
                        Console.WriteLine("{0, -20}{1,-20}{2,-20}{3,-20}{4,-20}${5,-20:0.00}", site.SiteId, site.MaxOccupancy, site.Accessible, site.MaxRvLength, site.Utilities, site.TotalCost);
                    }

                    Console.WriteLine();
                    Console.WriteLine("Which site should be reserved (enter 0 to cancel)?__");
                    Console.WriteLine();
                    int siteId = int.Parse(Console.ReadLine());
                    if (siteId == 0)
                    {
                        Console.Clear();
                        ViewParks();
                    }
                    Console.WriteLine();
                    Console.WriteLine("What name should the reservation be made under? __");
                    string name = Console.ReadLine();
                    Console.WriteLine();

                    ReservationSqlDAL newRes = new ReservationSqlDAL(connectionString);
                    int reservationId        = newRes.SetUpReservation(siteId, name, toDate, fromDate);

                    Console.WriteLine($"The reservation has been made and the confirmation id is {reservationId}");
                    Console.WriteLine();
                }
            }
            else
            {
                ViewCampGrounds(parkId);
            }
        }