Exemplo n.º 1
0
        public void GetCampgroundsAtPark_InsertedCampgroundExists()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                CampgroundSqlDAL testClass = new CampgroundSqlDAL(connectionString);

                Park tempPark = new Park();
                tempPark.Area           = 0;
                tempPark.Description    = "TEST DESCRIPTION";
                tempPark.Establish_Date = new DateTime(2000, 1, 1).Date;
                tempPark.Location       = "TEST LOCATION";
                tempPark.Name           = "TEST PARK";
                tempPark.Visitors       = 0;
                int tempPark_parkId = ParkSqlDALTests.InsertFakePark(tempPark);

                Campground testCamp = new Campground();
                testCamp.Daily_Fee     = 5.00M;
                testCamp.Name          = "Slimy Valley";
                testCamp.Open_From_MM  = 5;
                testCamp.Open_To_MM    = 6;
                testCamp.Park_Id       = tempPark_parkId;
                testCamp.Campground_Id = InsertFakeCampground(testCamp);

                Campground insertedCampground = testClass.GetCampgroundsAtPark(tempPark_parkId).First();

                Assert.IsNotNull(insertedCampground);
            }
        }
        /// <summary>
        /// Displays all campgrounds at the selected park.
        /// </summary>
        /// <param name="park"></param>
        /// <returns></returns>
        private List <Campground> DisplayCampgroundsList(Park park)
        {
            Console.Clear();
            CampgroundSqlDAL  cgDAL       = new CampgroundSqlDAL(ConnectionString);
            List <Campground> campgrounds = cgDAL.GetCampgroundsAtPark(park.Park_id);

            campgrounds.Insert(0, null);

            Console.WriteLine("".PadRight(5) + Campground.Header);
            for (int i = 1; i < campgrounds.Count; i++)
            {
                Console.WriteLine($"#{i,-1}   {campgrounds[i]}");
            }
            Console.WriteLine();

            return(campgrounds);
        }
        /// <summary>
        /// Gets date range from user, checks for available sites, and allows for reservations.
        /// For searching an entire park.
        /// </summary>
        /// <param name="park"></param>
        private void ManageAvailableSiteSearch(Park park)
        {
            List <Site> availableSites = new List <Site>();
            DateTime    arrivalDate    = new DateTime();
            DateTime    departureDate  = new DateTime();

            while (availableSites.Count == 0)
            {
                Tuple <DateTime, DateTime> dateRange = GetDateRange();
                if (dateRange == null)
                {
                    return;
                }
                arrivalDate   = dateRange.Item1;
                departureDate = dateRange.Item2;
                int numberOfNights = (int)(departureDate - arrivalDate).TotalDays;
                Console.WriteLine();

                CampgroundSqlDAL  cgDAL       = new CampgroundSqlDAL(ConnectionString);
                List <Campground> campgrounds = cgDAL.GetCampgroundsAtPark(park.Park_id);

                availableSites = SearchForAvailableSites(campgrounds, arrivalDate, departureDate);

                if (IsClosed(campgrounds, arrivalDate, departureDate))
                {
                    Console.WriteLine("One or more campgrounds are closed for part or all of your date range.");
                }

                if (availableSites.Count == 0)
                {
                    string wantsAlternateRange = CLIHelper.GetString(
                        "No available sites. Would you like to enter an alternate date range? (yes or no): ");

                    if (wantsAlternateRange.ToLower() != "yes")
                    {
                        return;
                    }
                }
            }

            ActOnAvailableSites(availableSites, arrivalDate, departureDate);
        }