コード例 #1
0
        /// <summary>
        /// Displays available sites
        /// </summary>
        /// <param name="campgroundId"></param>
        /// <param name="arrival"></param>
        /// <param name="departure"></param>
        private void DisplayAvailableSites(int campgroundId, DateTime arrival, DateTime departure)
        {
            Console.Clear();
            List <SiteItem> availSites = _db.GetAvailableSiteItems(campgroundId, arrival, departure);

            if (availSites.Count == 0)
            {
                bool exit = false;
                while (!exit)
                {
                    Console.WriteLine("No available sites for those dates.");
                    string response = CLIHelper.GetString("Would you like to enter an alternate date range? (Y / N) ");
                    if (response.Equals("Y") || response.Equals("y"))
                    {
                        (DateTime arrivalDate, DateTime departureDate) = CLIHelper.GetValidReservationWindow();
                        DisplayAvailableSites(campgroundId, arrivalDate, departureDate);
                    }
                    else if (response.Equals("N") || response.Equals("n"))
                    {
                        exit = true;
                    }
                    else
                    {
                        DisplayInvalidOption();
                    }
                }
            }
            else
            {
                Console.WriteLine("Results Matching Your Search Criteria");

                DisplaySiteDetail(campgroundId, availSites);

                int siteSelection = SelectSite(availSites);

                if (siteSelection != 0)
                {
                    string reservationName = CLIHelper.GetString("What name should the reservation be made under? ");

                    ReservationItem reservation = new ReservationItem();
                    reservation.SiteId     = siteSelection;
                    reservation.Name       = reservationName;
                    reservation.FromDate   = arrival;
                    reservation.ToDate     = departure;
                    reservation.CreateDate = DateTime.Now;

                    int userId = _userMgr.User.Id;

                    int reservationId = -1;

                    try
                    {
                        reservationId = _db.MakeReservation(reservation, userId);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("There was an error in your request, returning to previous screen.");
                        DisplayAvailableSites(campgroundId, arrival, departure);
                    }
                    SuccessFulReservation(reservationName, reservationId);
                }
                ParkMainMenu();
            }
        }