コード例 #1
0
        private void FindAvailableSitesMenu()
        {
            int          duration;
            IList <Site> sites;
            DateTime     desiredArrival;
            DateTime     desiredDeparture;

            System.Console.WriteLine();
            System.Console.WriteLine();
            System.Console.WriteLine("Enter ID# of desired campground (enter 0 to cancel):");
            int desiredCampgroundId = int.Parse(Console.ReadLine());

            if (desiredCampgroundId == 0)
            {
                return;
            }
            while (true)
            {
                System.Console.WriteLine("What is the arrival date? yyyy/mm/dd");
                desiredArrival = DateTime.Parse(Console.ReadLine());
                System.Console.WriteLine("What is the departure date? yyyy/mm/dd");
                desiredDeparture = DateTime.Parse(Console.ReadLine());
                System.Console.WriteLine();
                System.Console.WriteLine();
                duration = (int)(desiredDeparture.Subtract(desiredArrival).TotalDays) + 1;
                sites    = siteDAO.ListAvailableSites(desiredCampgroundId, desiredArrival, desiredDeparture);
                if (sites.Count == 0)
                {
                    System.Console.WriteLine("We're sorry, no sites were available within those dates, please enter another date range and try again");
                    Thread.Sleep(4000);
                    continue;
                }
                else
                {
                    break;
                }
            }

            printSiteListHeading();

            foreach (var site in sites)
            {
                printSiteListing(site, duration);
            }
            System.Console.Write("Which site should be reserved (enter 0 to cancel)? ");
            int selectedSiteNum = int.Parse(Console.ReadLine());
            int selectedSiteId  = 0;

            foreach (Site site in sites)
            {
                if (site.SiteNumber == selectedSiteNum)
                {
                    selectedSiteId = site.SiteId;
                }
            }
            if (selectedSiteId == 0)
            {
                return;
            }

            System.Console.Write("What name should the reservation be made under? ");
            string reservationName = Console.ReadLine();

            int conformationNumber = reservationDAO.MakeReservation(selectedSiteId, reservationName, desiredArrival, desiredDeparture);

            System.Console.WriteLine($"The reservation has been made and the conformation id is {conformationNumber}");
            Console.ReadLine();
        }