示例#1
0
        private void AskForReservationSiteAndName()
        {
            bool   isItParseable = false;
            string input         = "";

            do
            {
                Console.Write("Which site should be reserved (enter 0 to cancel)? ");
                input         = Console.ReadLine();
                isItParseable = int.TryParse(input, out UserInputForSite);
            } while ((!SiteSelector.ContainsKey(input) && UserInputForSite != 0) || !isItParseable);

            if (UserInputForSite == 0)
            {
                SiteSelector.Clear();
                DisplayParkInformation();
                DisplayCampgroundMenu();
                return;
            }
            else
            {
                Console.Write("What name should the reservation be made under? ");
                NameForReservation = Console.ReadLine();

                Console.WriteLine();
                int reservationId = reservationDAO.BookReservation(campgrounds[UserInputForCampground], SiteSelector.GetValueOrDefault(input), NameForReservation, ArrivalDate, DepartureDate);
                Console.WriteLine($"The reservation has been made and the confirmation id is {reservationId}. Your price was {TotalCost:C2}. Thank you.");
                Thread.Sleep(7000);
                SiteSelector.Clear();
                DisplayParkInformation();
                DisplayCampgroundMenu();
                return;
            }
        }
示例#2
0
        /// <summary>
        /// The override of ExecuteSelection handles whatever selection was made by the user.
        /// This is where any business logic is executed.
        /// </summary>
        /// <param name="choice">"Key" of the user's menu selection</param>
        /// <returns></returns>
        protected override bool ExecuteSelection(string choice)
        {
            if (menuOptions.ContainsKey(choice))
            {
                if (choice == "0")
                {
                    return(false);
                }
                int      intChoice = int.Parse(choice);
                DateTime startDate = GetDate("What is the arrival date?");
                DateTime endDate   = GetDate("What is the departure date?");

                IList <Campground> cg   = CampgroundDAO.GetCampgrounds(park.ParkId);
                Campground         camp = new Campground();
                foreach (Campground c in cg)
                {
                    if (c.CampgroundId == intChoice)
                    {
                        camp = c;
                    }
                }
                decimal fee = camp.DailyFee * Convert.ToDecimal((endDate - startDate).TotalDays);

                IList <Site> sites = SiteDAO.AvailableSites(intChoice, startDate, endDate);
                if (sites.Count == 0)
                {
                    string answer = GetString("There are no available sites in that date range, would you like to enter an alternate date range? (Y/N)");
                    if (answer == "Y")
                    {
                        return(false);
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine($"{"Site No.", -10}{"Max Occup.", -15}{"Accessible", -15}{"Max RV Length", -15}{"Utility", -15}{"Cost", -10}");
                    Console.WriteLine("-----------------------------------------------------------------------------");

                    foreach (Site site in sites)
                    {
                        Console.WriteLine($"{site.SiteNumber, -10}{site.MaxOccupancy, -15}{site.IsAccessible, -15}{site.MaxRVLength, -15}{site.HasUtilities, -15}{fee, -10:C}");
                    }

                    Console.WriteLine();
                    int site1 = GetInteger("Which site should be reserved? (enter 0 to cancel)");
                    if (site1 == 0)
                    {
                        return(false);
                    }
                    string name = GetString("What name should the reservation be made under?");
                    int    conf = ReservationDAO.BookReservation(name, site1, startDate, endDate);
                    Console.WriteLine();
                    Console.WriteLine($"The reservation has been made and the confirmation id is {conf}.");
                    Console.ReadLine();
                }
            }

            return(true);
        }
示例#3
0
        private void PrintReservationSearchPrompt(Park selectedPark)
        {
            IList <Campground> campgrounds = campgroundDAO.GetCampgrounds(selectedPark.ParkId);

            Console.Clear();
            Console.WriteLine("Search for Campground Reservation");
            Console.WriteLine();

            Console.WriteLine($"        Name                             Open           Close         Daily Fee");

            foreach (Campground campground in campgrounds)
            {
                Console.WriteLine($"#{campground.CampgroundId,-5}{campground.Name,-35}{campground.FromMonth,-15}{campground.ToMonth,-15}{$"{campground.DailyFee:C2}",-10}");
            }
            Console.WriteLine();
            int campgroundId = CLIHelper.GetInteger(" Which Campground (enter 0 to cancel)?:");

            if (campgroundId == 0)
            {
                return;
            }

            bool isValidCampground = false;

            foreach (Campground campground in campgrounds)
            {
                if (campgroundId == campground.CampgroundId)
                {
                    isValidCampground = true;
                }
            }

            if (!isValidCampground)
            {
                Console.WriteLine("Please enter a valid campground id..");
                Console.ReadLine();
                PrintReservationSearchPrompt(selectedPark);
            }

            DateTime arrival   = CLIHelper.GetDateTime("What is the arrival date? (as mm/dd/yyyy):");
            DateTime departure = CLIHelper.GetDateTime("What is the departure date? (as mm/dd/yyyy):");

            Console.WriteLine();

            if (departure < arrival)
            {
                Console.WriteLine("The departure date must be after the arrival date");
                Console.ReadLine();
                PrintReservationSearchPrompt(selectedPark);
                return;
            }

            TimeSpan dateRange = departure.Date - arrival.Date;

            int     daysOfStay = dateRange.Days;
            decimal dailyFee   = 0;

            IList <Site> sites = siteDAO.GetAvailableSites(campgroundId, arrival, departure);

            foreach (Campground campground in campgrounds)
            {
                if (campground.CampgroundId == campgroundId)
                {
                    dailyFee = campground.DailyFee;
                }
            }

            decimal costOfTotalStay = dailyFee * daysOfStay;

            Console.WriteLine("Results Matching Your Search Criteria");
            Console.WriteLine($"{"Site No.",-10}{"Max Occup.", -12}{"Accessible?",-12}{"Max RV Length",-14}{"Utility",-10}{"Cost",-8}");

            foreach (Site site in sites)
            {
                string rvLength   = "N/A";
                string accessible = "No";
                string utility    = "N/A";

                if (site.Utilities == true)
                {
                    utility = "Yes";
                }

                if (site.Accessible == true)
                {
                    accessible = "Yes";
                }

                if (site.MaxRVLength != 0)
                {
                    rvLength = site.MaxRVLength.ToString();
                }
                Console.WriteLine($"{site.SiteId,-10}{site.MaxOccupancy,-12}{accessible,-12}{rvLength,-14}{utility,-10}{$"{costOfTotalStay:C2}",-8}");
            }
            Console.WriteLine();
            int siteId = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?");

            if (siteId == 0)
            {
                return;
            }

            bool isValidSite = false;

            foreach (Site site in sites)
            {
                if (siteId == site.SiteId)
                {
                    isValidSite = true;
                }
            }

            if (!isValidSite)
            {
                Console.WriteLine("Please enter a valid site id..");
                Console.ReadLine();
                PrintReservationSearchPrompt(selectedPark);
            }

            string name = CLIHelper.GetString("What name should the reservation be made under?");

            Console.WriteLine();

            Reservation reservation = new Reservation
            {
                SiteId     = siteId,
                Name       = name,
                FromDate   = arrival,
                ToDate     = departure,
                CreateDate = DateTime.Now,
            };

            reservationDAO.BookReservation(reservation);
            Console.WriteLine("Thanks for booking your reservation, press enter to return to main menu");
            Console.ReadLine();
        }