コード例 #1
0
        public void GetAllCampgroundsFromParkTest() //List<Campground> GetAllCampgroundsFromPark(int parkId)
        {
            //Arange
            CampgroundSqlDal campgroundSqlDal = new CampgroundSqlDal(connectionString);

            //ACT
            List <Campground> campgrounds = campgroundSqlDal.GetAllCampgroundsFromPark(1);

            //Assert
            Assert.IsNotNull(campgrounds, "Campgrounds list is empty!");
            Assert.AreEqual(campgroundCount, campgrounds.Count, $"Expected a count of {campgroundCount} for campgrounds");

            //Insert Assert
            bool found = false;

            foreach (Campground campground in campgrounds)
            {
                if (campground.Name == "Test Campground")
                {
                    found = true;
                    break;
                }
            }
            Assert.IsTrue(found, "Could not find Test Campground named Test Campground");
        }
        public void PrintAllCampgroundInfoInPark(Park park)
        {
            Console.WriteLine(park.Name + "\n");
            Console.WriteLine("Id".PadRight(5) + "Name".PadRight(35) + "Open".PadRight(20) + "Close".PadRight(20) + "Daily Fee\n");

            CampgroundSqlDal  campgroundSqlDal = new CampgroundSqlDal(DatabaseConnection);
            List <Campground> campgrounds      = campgroundSqlDal.GetAllCampgroundsFromPark(park.Id);

            foreach (Campground campground in campgrounds)
            {
                Console.WriteLine(campground);
            }
        }
        public void SearchForAvailableReservationScreen(Park park)
        {
            SiteSqlDal        siteSqlDal        = new SiteSqlDal(DatabaseConnection);
            CampgroundSqlDal  campgroundSqlDal  = new CampgroundSqlDal(DatabaseConnection);
            ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection);
            List <Campground> campgrounds       = campgroundSqlDal.GetAllCampgroundsFromPark(park.Id);

            //Search for valid campground
            bool done = false;

            while (!done)
            {
                Console.Clear();
                Console.WriteLine("Search for Campground Reservation: ");
                PrintAllCampgroundInfoInPark(park);

                int userInputCampgroundId = CLIHelper.GetInteger("\nWhich Campground number (Enter 0 to cancel)?");
                if (userInputCampgroundId == 0)
                {
                    Console.WriteLine("Cancelled! Press any key to continue.");
                    Console.ReadKey();
                    return;
                }

                if (GetCampgroundById(userInputCampgroundId, campgrounds) == null)
                {
                    Console.WriteLine("Not a valid campground! Press any key to continue.");
                    Console.ReadKey();
                    return;
                }

                //Once valid campground has been chosen --> Get good dates for query
                DateTime    checkIn  = CLIHelper.GetDateTime("Check-in date: ");
                DateTime    checkOut = CLIHelper.GetDateTime("Check-out date: ");
                List <Site> availableSitesFromCampgrounds = new List <Site>();
                bool        gotDates = false;
                bool        showReservationPrompt = false;
                while (!gotDates)
                {
                    availableSitesFromCampgrounds = siteSqlDal.GetAvailableSitesFromCampground(userInputCampgroundId, checkIn, checkOut);
                    if (checkOut.CompareTo(checkIn) <= 0)
                    {
                        Console.WriteLine("Cannot check-out earlier or same day as check-in.  Press any key to continue");
                        Console.ReadKey();
                        showReservationPrompt = false;
                        gotDates = true;
                        //could allow user a choice to return or enter new dates
                    }
                    else if (availableSitesFromCampgrounds.Count < 1)
                    {
                        string dateReset = CLIHelper.GetString("\nThere are no available sites. \nWould you like to enter an alternate date range?\n\tYes or No?").ToLower();
                        if (dateReset == "yes" || dateReset == "y")
                        {
                            Console.WriteLine();
                            checkIn  = CLIHelper.GetDateTime("Check-in date: ");
                            checkOut = CLIHelper.GetDateTime("Check-out date: ");
                            gotDates = false;
                        }
                        else if (dateReset == "no" || dateReset == "n")
                        {
                            gotDates = true;
                        }
                        else
                        {
                            Console.WriteLine("Invalid input. Try again");
                            gotDates = false;
                        }
                    }
                    else
                    {
                        showReservationPrompt = true;
                        gotDates = true;
                    }
                }
                if (showReservationPrompt)
                {
                    int daysReserved = checkOut.Subtract(checkIn).Days;
                    Console.WriteLine("Site Id".PadRight(10) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(20) + "Utility".PadRight(15) + "Cost\n");
                    foreach (Site site in availableSitesFromCampgrounds)
                    {
                        Console.WriteLine(site.GetPrintString(daysReserved, GetCampgroundById(userInputCampgroundId, campgrounds).DailyFee));
                    }
                    Console.WriteLine();

                    MakeReservationPrompts(checkIn, checkOut, availableSitesFromCampgrounds);
                    done = true;
                }
            }
        }