コード例 #1
0
        //creates a reservation based on the user's chosen dates and siteId
        private void CreateReservation(DateTime arriveDate, DateTime departDate)
        {
            Console.ForegroundColor = (ConsoleColor.Magenta);
            int siteIdSelection = CliHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?: ");

            //if user chooses 0 then return to original menu
            if (siteIdSelection == 0)
            {
                Console.Clear();
                return;
            }
            //else statement proceeds with good reservation
            else
            {
                Console.ForegroundColor = (ConsoleColor.Magenta);
                string reservedName = CliHelper.GetString("What name should the reservation be made under?: ");

                Reservation reservation = new Reservation
                {
                    siteID   = siteIdSelection,
                    name     = reservedName,
                    fromDate = arriveDate,
                    toDate   = departDate
                };

                int reservationId = reservationDAO.CreateReservation(reservation);

                if (reservationId > 0)
                {
                    Console.ForegroundColor = (ConsoleColor.Magenta);
                    Console.WriteLine("Your reservation has been added");
                    Console.WriteLine();
                }
                else
                {
                    Console.ForegroundColor = (ConsoleColor.Red);
                    Console.WriteLine("Error, try again");
                    Console.WriteLine();
                }
            }
        }
コード例 #2
0
        //Gets the park details for the park selected by the user
        private void GetParkDetails()
        {
            this.parkId = CliHelper.GetInteger("Please choose a park for more details: ");
            IList <Park> parks = parkDAO.GetParkDetails(this.parkId);

            Console.Clear();

            foreach (Park info in parks)
            {
                Console.WriteLine($"{info.name} National Park");
                Console.WriteLine($"Location: {info.location}");
                Console.WriteLine($"Established: {info.establish_date}");
                Console.WriteLine($"Area: {info.area:N0} sq km");
                Console.WriteLine($"Annual Visitors: {info.visitors:N0}");
                Console.WriteLine();
                Console.WriteLine($"{info.description}");
                Console.WriteLine();

                CampGroundMenu();
            }
        }
コード例 #3
0
        //searches for available reservation based on the dates and siteId requested by the user
        private void SearchReservation(IList <CampGround> campGrounds)
        {
            Console.ForegroundColor = (ConsoleColor.Magenta);
            Console.WriteLine("Search for Available Campground Sites");
            int campgroundId = CliHelper.GetInteger("Which campground (enter 0 to cancel)?: ");

            //if statement to return user if no available sites for the specified dates
            if (campgroundId == 0)
            {
                Console.Clear();
                return;
            }

            //if statement that calls method to have user try again if their choice is not one of the displayed campgrounds
            if (!ValidateCampGroundId(campgroundId, campGrounds))
            {
                Console.ForegroundColor = (ConsoleColor.Red);
                Console.WriteLine("Invalid choice. Please try again.");
                Console.WriteLine("");
                SearchReservation(campGrounds);
                return;
            }

            //allows user to input their desired dates
            Console.ForegroundColor = (ConsoleColor.Magenta);
            DateTime arriveDate = CliHelper.GetDateTime("What is the arrival date? (MM/DD/YYYY): ");
            DateTime departDate = CliHelper.GetDateTime("What is the departure date? (MM/DD/YYYY): ");

            IList <Site> sites = siteDAO.SearchReservation(campgroundId, arriveDate, departDate);

            //if statement that lets user try again because there is nothing available
            if (sites.Count == 0)
            {
                Console.Clear();
                Console.ForegroundColor = (ConsoleColor.Red);
                Console.WriteLine("There are no sites available for those dates, try again");
                return;
            }
            //else statement proceeds with available reservation
            else
            {
                Console.ForegroundColor = (ConsoleColor.Magenta);
                CampGround campGround = campGroundDAO.GetSingleCampGround(campgroundId);

                decimal cost = campGround.daily_fee * (decimal)(departDate - arriveDate).TotalDays;

                Console.WriteLine();
                Console.WriteLine("Site NO.".PadRight(20) + "MAX OCCUPANCY".PadRight(20) + "ACCESSIBLE".PadRight(20) + "MAX RV LENGTH".PadRight(20) + "UTILITY".PadRight(20) + "COST");
                Console.WriteLine();

                //foreach loops displays the available sites
                foreach (Site site in sites)
                {
                    Console.ForegroundColor = (ConsoleColor.Magenta);
                    Console.WriteLine($"#{site.siteId}".PadRight(20) + $"{site.maxOccupancy}".PadRight(20) + $"{site.accessible}".PadRight(20) + $"{site.maxRvLength}".PadRight(20) + $"{site.utilities}".PadRight(20) + $"{cost:C2}");
                }
                Console.ForegroundColor = (ConsoleColor.Magenta);
                Console.WriteLine();
                CreateReservation(arriveDate, departDate);
            }
        }