Esempio n. 1
0
        public void SearchAndMakeReservationMenu(int venueNum)
        {
            venueNum += 1;
            IList <Venue>       venues       = venueDAO.GetVenues();
            IList <Space>       spaces       = spaceDAO.GetVenueSpaces(venueNum);
            IList <Reservation> reservations = reservationDAO.GetReservations(spaces);
            DateTime            startDate    = new DateTime();
            int numOfDays       = 0;
            int peopleAttending = 0;

            bool done = false;

            while (!done)
            {
                //different try catch statements for each parse check because a different error message is returned
                try
                {
                    Console.WriteLine("Search for available spaces");
                    Console.WriteLine("When do you need the space? MM/DD/YEAR");
                    string inputDay = Console.ReadLine();

                    startDate = DateTime.Parse(inputDay);
                    if (startDate < DateTime.Now)
                    {
                        Console.WriteLine("Please input a future date!");
                        return;
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Please enter your date as a Month Number/Day/Full Year");
                    return;
                }

                Console.WriteLine("How many days will you need the space?");
                string dayNumber = Console.ReadLine();
                try
                {
                    numOfDays = Convert.ToInt32(dayNumber);
                    if (numOfDays <= 0)
                    {
                        Console.WriteLine("Please input a positive number of days");
                        return;
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Please enter the length of your reservation as a number");
                    return;
                }

                Console.WriteLine("How many people will be in attendance?");
                string attendNum = Console.ReadLine();

                try
                {
                    peopleAttending = Convert.ToInt32(attendNum);
                    if (peopleAttending <= 0)
                    {
                        Console.WriteLine("Please input the number of people attending");
                        return;
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Please enter the expected attendance as a number");
                    return;
                }

                List <Space> toRemove = new List <Space>();
                //creates a list of items to remove from the list of Spaces - each bool check adds to the list
                foreach (Space space in spaces)
                {
                    bool available = reservationDAO.IsDateAvailable(reservations, space, startDate, numOfDays);
                    if (available == false)
                    {
                        toRemove.Add(space);
                    }
                }
                foreach (Space space in spaces)
                {
                    bool available = reservationDAO.IsSpaceOperating(space, startDate, numOfDays);
                    if (available == false)
                    {
                        toRemove.Add(space);
                    }
                }
                foreach (Space space in spaces)
                {
                    bool available = reservationDAO.IsBookingBelowMaxOcc(space, peopleAttending);
                    if (available == false)
                    {
                        toRemove.Add(space);
                    }
                }
                foreach (Space removal in toRemove)
                {
                    spaces.Remove(removal);
                }
                //removes all Space objects that are in the list toRemove from the list spaces

                Console.WriteLine("");
                Console.WriteLine("Space #".PadRight(9) + "Name".PadRight(25) + "Daily Rate".PadRight(12) +
                                  "Max Occup".PadRight(10) + "Accessible?".PadRight(12) + "Total Cost".PadRight(13));
                foreach (Space space in spaces)
                {
                    decimal totalCost = space.DailyRate * numOfDays;
                    Console.WriteLine(space.Id.ToString().PadRight(9) + space.Name.PadRight(25) +
                                      space.DailyRate.ToString("C").PadRight(12) + space.MaxOccupancy.ToString().PadRight(10) +
                                      space.IsAccessible.ToString().PadRight(12) + totalCost.ToString("C"));
                }
                Console.WriteLine("");
                Console.WriteLine("Which space would you like to reserve? (Please enter Space #)");
                string spaceIDChosen = Console.ReadLine();
                Console.WriteLine("Who is this reservation for?");
                string reservedFor = Console.ReadLine();

                //ADD METHOD TO GO TO CONFIRMATION AND TO ADD TO RESERVATION DATABASE
                PrintReservationConfirmation(venueNum, spaceIDChosen, reservedFor, startDate, numOfDays, peopleAttending);

                done = true;
            }
        }