示例#1
0
        public List <Site> WriteTopFiveSites(List <Site> listOpenSites, string campsiteSelection)
        {
            List <Site> topFiveSites = new List <Site>();
            int         dateDiff     = ParkObject.GetDateDifference(_reservationStartDate, _reservationEndDate); //calculates how many days in reservation
            int         totalFee     = ParkObject.GetTotalFee(_campgroundNumber, dateDiff);

            if (listOpenSites.Count >= 5)
            {
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine($"Campsite {listOpenSites.ElementAt(i).ID} is available and your total cost will be ${totalFee}.");
                    topFiveSites.Add(listOpenSites[i]);
                }
            }
            else if (listOpenSites.Count > 0)
            {
                foreach (Site item in listOpenSites)
                {
                    Console.WriteLine($"Campsite {item.ID} is available and your total cost will be ${totalFee}.");
                    topFiveSites.Add(item);
                }
            }
            else
            {
                Console.WriteLine("No campsites are available at requested time.");
            }
            return(topFiveSites);
        }
示例#2
0
        public void SelectCampsite(List <Site> topFiveSites)
        {
            Console.WriteLine("Select an available camp site: ");
            //Method for printing Campground and Availability
            Console.Write("Which camp site would you prefer? (enter 0 to cancel) ");
            string campsiteSelection = Console.ReadLine();
            bool   print             = false;
            bool   exit = false;

            while (!exit)
            {
                if (campsiteSelection == "0")
                {
                    exit = true;
                }
                else //needed an else so the entry (to exit or for a successful choice) didn't get run through the try/catch
                {
                    try
                    {
                        //bool print = false;
                        foreach (var item in topFiveSites)
                        {
                            if (item.ID == campsiteSelection) //causing issues with looping and printing 'Invalid' after valid campsite selection
                            {
                                Console.WriteLine("What name would you like to reserve this under?");
                                string nameForReservation = Console.ReadLine();
                                string message            = ParkObject.InsertReservationToTable(campsiteSelection, nameForReservation, _reservationStartDate, _reservationEndDate);
                                int    dateDiff           = ParkObject.GetDateDifference(_reservationStartDate, _reservationEndDate); //calculates how many days in reservation
                                int    totalFee           = ParkObject.GetTotalFee(_campgroundNumber, dateDiff);
                                Console.WriteLine($"{message}  Your reservation number is {ParkObject.ReservationID()} and your total cost is ${totalFee}." +
                                                  $"\nPress any key to return to main menu."); //need to move total cost to display of camp sites for comparison
                                exit = true;
                                Console.ReadKey();
                            }
                            else if (item == topFiveSites[topFiveSites.Count - 1])
                            {
                                Console.WriteLine("Invalid entry. Please try again.");
                                campsiteSelection = Console.ReadLine();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            if (print)
            {
                Console.WriteLine("Invalid entry.");
            }
        }