Exemplo n.º 1
0
        public void AddReservationTest()
        {
            ReservationSqlDAL dal = new ReservationSqlDAL(ConnectionString);

            int initialCount = GetRowCount();

            Reservation reservation = new Reservation();

            reservation.ReservationId = 2;
            reservation.SiteId        = 1;
            reservation.Name          = "Art Vandelay Reservation";
            reservation.StartDate     = new DateTime(2018, 07, 01);
            reservation.EndDate       = new DateTime(2018, 07, 10);
            reservation.CreateDate    = DateTime.Now;

            DateTime[] dateRange = new DateTime[2] {
                reservation.StartDate, reservation.EndDate
            };

            var reservations = dal.AddReservation(reservation.SiteId, reservation.Name, dateRange);

            int finalCount = GetRowCount();

            Assert.AreEqual(initialCount + 1, finalCount);
        }
        public void GetAvailableSites_AdjacentToNext_IsAvailable()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                // Arrange
                ManualInitialize();
                SiteSqlDAL        testClass         = new SiteSqlDAL(connectionString);
                DateTime          testStartDate     = new DateTime(2000, 6, 10).Date;
                DateTime          testEndDate       = new DateTime(2000, 6, 20).Date;
                DateTime          conflictStartDate = new DateTime(2000, 6, 20).Date;
                DateTime          conflictEndDate   = new DateTime(2000, 6, 30).Date;
                ReservationSqlDAL rDal            = new ReservationSqlDAL(connectionString);
                Reservation       tempReservation = new Reservation();
                tempReservation.Site_Id   = siteId;
                tempReservation.Name      = "TEMP RESERVATION";
                tempReservation.From_Date = conflictStartDate;
                tempReservation.To_Date   = conflictEndDate;
                rDal.AddReservation(tempReservation);

                // Act
                List <Site> availableSites = testClass.GetAvailableSites(testCamp, testStartDate, testEndDate);

                // Assert
                Assert.AreEqual(1, availableSites.Count);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Select from available sites in selected campground
        /// </summary>
        /// <param name="campground"></param>
        /// <param name="arrival"></param>
        /// <param name="departure"></param>
        private void SiteSelectionMenu(Campground campground, DateTime arrival, DateTime departure)
        {
            Reservation reserve = new Reservation();

            reserve.FromDate = arrival;
            reserve.ToDate   = departure;
            bool quit = false;

            while (!quit)
            {
                SiteSqlDAL  siteSqlDAL = new SiteSqlDAL(_connectionString);
                List <Site> resList    = siteSqlDAL.GetAvailalableSitesInCampground(campground.CampgroundId, arrival, departure);
                TimeSpan    interval   = reserve.ToDate - reserve.FromDate;
                decimal     cost       = interval.Days * campground.DailyFee;

                if (resList.Count == 0)
                {
                    Console.WriteLine("\nNo sites available for the dates provided.");
                }
                else
                {
                    DisplayAvailableSites(resList, cost);

                    reserve.SiteId = 0;
                    int selection = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?");
                    if (selection < 0)
                    {
                        Console.WriteLine(" Invalid selection. Please try again.");
                    }
                    //else if (selection == 0)
                    //{
                    //    quit = true;
                    //}
                    else if (selection > 0)
                    {
                        //var site = resList.Find(m => m.SiteId == selection);

                        for (int i = 0; i < resList.Count; i++)
                        {
                            if (resList[i].SiteNumber == selection)
                            {
                                reserve.SiteId = resList[i].SiteId;
                            }
                        }
                        if (reserve.SiteId == 0)
                        {
                            Console.WriteLine(" Invalid selection. Please try again.");
                        }
                    }
                    Console.WriteLine("What name Should the reservation be made under?");
                    reserve.Name = Console.ReadLine();
                    ReservationSqlDAL reservationSqlDAL = new ReservationSqlDAL(_connectionString);
                    reserve = reservationSqlDAL.AddReservation(reserve);
                    Console.WriteLine($"The reservation has been made and the confirmation id is {reserve.ReservationId}");

                    quit = true;
                }
            }
        }
        /// <summary>
        /// Adds a reservation to the database at the selected site, under the provided name, and for
        /// the provided duration.
        /// </summary>
        /// <param name="arrivalDate">The date that the guest will arrive at the site.</param>
        /// <param name="departureDate">The date that the guest will leave the site.</param>
        /// <param name="name">A name to identify the guest by.</param>
        /// <param name="site">The site being reserved.</param>
        private void MakeReservation(DateTime arrivalDate, DateTime departureDate, string name, Site site)
        {
            Reservation newReservation = new Reservation();

            newReservation.Site_Id   = site.Site_Id;
            newReservation.From_Date = arrivalDate;
            newReservation.To_Date   = departureDate;
            newReservation.Name      = name;

            ReservationSqlDAL rDal      = new ReservationSqlDAL(ConnectionString);
            int reservationConfirmation = rDal.AddReservation(newReservation);

            Console.WriteLine("The reservation has been made and the confirmation id is {0}", reservationConfirmation);
        }
        public void AddReservation_Succeeds()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                // Arrange
                ReservationSqlDAL testClass = new ReservationSqlDAL(connectionString);
                ManualInitialize();
                DateTime    testStartDate   = new DateTime(2000, 6, 10).Date;
                DateTime    testEndDate     = new DateTime(2000, 6, 20).Date;
                Reservation tempReservation = new Reservation();
                tempReservation.Site_Id   = siteId;
                tempReservation.Name      = "TEMP RESERVATION";
                tempReservation.From_Date = testStartDate;
                tempReservation.To_Date   = testEndDate;

                // Act
                int reservationId = testClass.AddReservation(tempReservation);

                // Assert
                Assert.IsTrue(reservationId > 0);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks the entered requested date range against existing reservations for that selected site at the selected campground at the selected park
        /// </summary>
        /// <param name="parkId"></param>
        /// <param name="campgroundId"></param>
        /// <param name="siteNumber"></param>
        /// <param name="desiredReservationDates"></param>
        /// <returns>Reservation at the selected site at the selected campground at the selected park</returns>
        private Reservation CheckAvailableReservation(int parkId, int campgroundId, int siteId, int siteNumber, DateTime[] desiredReservationDates)
        {
            ReservationSqlDAL   dal                   = new ReservationSqlDAL(DatabaseConnection);
            IList <Reservation> reservations          = dal.GetReservations(parkId, campgroundId, siteNumber);
            Reservation         successfulReservation = new Reservation();
            bool isValidReservation                   = true;

            foreach (var reservation in reservations)
            {
                if ((desiredReservationDates[0] >= reservation.StartDate && desiredReservationDates[0] <= reservation.EndDate) || (desiredReservationDates[1] >= reservation.StartDate && desiredReservationDates[1] <= reservation.EndDate))
                {
                    isValidReservation = false;
                    Console.WriteLine("Reservation already booked during all or part of this date range. Please select another date range.");
                    break;
                }
            }
            if (isValidReservation)
            {
                Console.Write("Please Enter Reservation Name: ");
                string reservationName = Console.ReadLine();
                successfulReservation = dal.AddReservation(siteId, reservationName, desiredReservationDates);
            }
            return(successfulReservation);
        }
    private void MainMenu()

    {
        Console.WriteLine(@"_________                         ________                                ___");
        Console.WriteLine(@"\_   ___ \_____    _____ ______  /  _____/______  ____  __ __  ____    __| _/");
        Console.WriteLine(@"/    \  \/\__  \  /     \\____ \/   \  __\_  __ \/  _ \|  |  \/    \  / __ | ");
        Console.WriteLine(@"\     \____/ __ \|  Y Y  \  |_> >    \_\  \  | \(  <_> )  |  /   |  \/ /_/ | ");
        Console.WriteLine(@" \______  (____  /__|_|  /   __/ \______  /__|   \____/|____/|___|  /\____ | ");
        Console.WriteLine(@"        \/     \/      \/|__|           \/                        \/      \/ ");
        Console.WriteLine(@"_________                                          ___ .__");
        Console.WriteLine(@"\______  \ ____   ______ ______________  _______ _/  |_|__| ____   ____  ");
        Console.WriteLine(@"|       _// __ \ /  ___// __ \_  __ \  \/ /\__  \\   __\  |/  _ \ /    \ ");
        Console.WriteLine(@"|    |   \  ___/ \___ \\  ___/|  | \/\   /  / __ \|  | |  (  <_> )   |  \");
        Console.WriteLine(@"|____|_  /\___  >____  >\___  >__|    \_/  (____  /__| |__|\____/|___|  /");
        Console.WriteLine(@"       \/     \/     \/     \/                  \/                    \/ ");

        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine("Welcome to the National Parks Reservation System.");
        Console.WriteLine("Please choose one of the parks listed below.");
        Console.WriteLine();

        //gives us a new park using the get GetParkNames Method
        IList <string> parks = GetParkNames();

        int parkCount = 1;

        //loops through the park list
        //gives each of the parks a number
        foreach (string p in parks)
        {
            Console.WriteLine($"{parkCount} - {p}");
            parkCount++;
        }

        Console.WriteLine($"{parks.Count + 1} - Quit");
        Console.WriteLine();
        int userInput = 0;

        //prompt user to enter teh park they want to go to
        //if they choose the quit number(n+1) it wil quit the program
        //if they are a jackass and enter in a huge number or a negative number
        //then it will keep promptinf them to enter in a real number
        do
        {
            userInput = (CLIHelper.GetInteger("Please Choose a Park Number: "));
        } while (userInput <= 0 || userInput > parks.Count + 1);

        if (userInput == parks.Count + 1)
        {
            return;
        }

        string parkName = parks[userInput - 1].ToString();

        ParksSqlDAL Parks = new ParksSqlDAL(connectionString);

        //creates a new dictionary with the parks data in it
        Dictionary <int, Park> parkDictionary = Parks.GetParkData(parkName);

        globalParkName = parkDictionary[1].Name;

        Console.Clear();
        Console.WriteLine("Park Information Screen");
        Console.WriteLine();
        Console.WriteLine($"Park Name: {parkDictionary[1].Name}");
        Console.WriteLine($"Location: {parkDictionary[1].Location}");
        Console.WriteLine($"Established: {parkDictionary[1].Established.ToShortDateString()}");
        Console.WriteLine($"Area: {string.Format("{0:n0}", parkDictionary[1].Area)}");
        Console.WriteLine($"Annual Visitors: {string.Format("{0:n0}", parkDictionary[1].VisitCount)}");
        Console.WriteLine();
        Console.WriteLine($"{parkDictionary[1].Description}");
        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine(" 1 - View all campgrounds");
        Console.WriteLine(" 2 - Search for Reservation.");
        Console.WriteLine(" 3 - Return to Previous Screen");
        Console.WriteLine();
        do
        {
            userInput = CLIHelper.GetInteger("Please Select a Command: ");

            if (userInput == 1)
            {
                //create a new campground
                //puts it in a dictionary
                //brings up the ground menu
                CampgroundSqlDAL             Campgrounds          = new CampgroundSqlDAL(connectionString);
                Dictionary <int, Campground> campGroundDictionary = Campgrounds.GetCampground(parkDictionary[1].Id);
                CampGroundMenu(campGroundDictionary);
            }
            else if (userInput == 2)
            {
            }
            else if (userInput == 3)
            {
                Console.Clear();
                MainMenu();
            }
            else
            {
                Console.WriteLine("Please make a valid choice");
            }
        } while (userInput != 1 || userInput != 2 || userInput != 3);


        void CampGroundMenu(Dictionary <int, Campground> campGroundDictionary)
        {
            int count = 1;

            Console.Clear();
            Console.WriteLine($"{globalParkName} Park Campgrounds");
            Console.WriteLine();
            Console.Write("Name".PadLeft(10));
            Console.Write("Open".PadLeft(30));
            Console.Write("Close".PadLeft(11));
            Console.WriteLine("Daily Fee".PadLeft(19));
            Console.WriteLine();

            Dictionary <int, int> siteIdDictionary = new Dictionary <int, int>();

            siteIdDictionary.Add(0, 0);
            foreach (KeyValuePair <int, Campground> kvp in campGroundDictionary)
            {
                Console.Write($"#{count,-5}");
                Console.Write("{1, -30}", kvp.Key, kvp.Value.Name);
                Console.Write("{1, -10}", kvp.Key,
                              CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(kvp.Value.Open));
                Console.Write("{1, -15}", kvp.Key,
                              CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(kvp.Value.Close));
                Console.Write("{1, -15}", kvp.Key, kvp.Value.Fee.ToString("C"));
                Console.WriteLine();
                siteIdDictionary.Add(count, kvp.Value.Id);
                count++;
            }

            if (reservation == false)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(" 1 - Search for Available Reservation.");
                Console.WriteLine(" 2 - Return to Previous Screen");
                Console.WriteLine();

                do
                {
                    userInput = CLIHelper.GetInteger("Please Select a Command: ");

                    if (userInput == 1)
                    {
                        //if the user inputs 1
                        // will set reservation varible to true
                        //then prompt you to enter the campground of your choice
                        reservation = true;
                        CampGroundMenu(campGroundDictionary);
                    }
                    else if (userInput == 2)
                    {
                        CampGroundMenu(campGroundDictionary);
                    }
                    else
                    {
                        Console.WriteLine("Please make a valid choice");
                    }
                } while (userInput != 1 || userInput != 2);
            }
            else
            {
                //when the user chooses 1 it starts the reservation menu
                ReservationMenu(campGroundDictionary, siteIdDictionary);
            }
        }

        void ReservationMenu(Dictionary <int, Campground> campGroundDictionary, Dictionary <int, int> siteIdDictionary)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            int campgroundChoice = CLIHelper.GetInteger("Which campground (enter 0 to cancel)?: ");

            if (campgroundChoice == 0)
            {
                //will bring back the menu choices
                Console.Clear();
                reservation = false;
                CampGroundMenu(campGroundDictionary);
            }
            else
            {
                campgroundChoice = siteIdDictionary[campgroundChoice];
            }
            Console.Clear();

            //prompts the user for arrival and departure dates
            DateTime arrivalDate = CLIHelper.GetDateTime("Please enter the date you will be arriving. (mm/dd/yyyy): ");

            arrivalDate = arrivalDate;

            DateTime departureDate = CLIHelper.GetDateTime("Please enter the date you will be departing. (mm/dd/yyyy): ");

            departureDate = departureDate;

            ReservationSqlDAL reservations = new ReservationSqlDAL(connectionString);

            //creates new dictionary to get open camp sites
            Dictionary <int, CampSite> reservationDictionary =
                reservations.GetOpenCampSites(campgroundChoice, arrivalDate, departureDate);

            Console.Clear();
            Console.WriteLine($"Results matching your search criteria");
            Console.WriteLine();
            Console.Write("Site No.".PadLeft(5));
            Console.Write("Max Occup.".PadLeft(12));
            Console.Write("Accessible?".PadLeft(12));
            Console.Write("Max RV Length".PadLeft(16));
            Console.Write("Utility".PadLeft(12));
            Console.Write("Total Cost".PadLeft(11));
            Console.WriteLine();


            if (reservationDictionary.Count < 1)
            {
                string userTemp = "";
                do
                {
                    //if no reservations are avalible then prompts user to choose new dates
                    Console.Clear();
                    userTemp = CLIHelper.GetString(
                        "No sites available for those dates.  Would you like to choose alternate dates? y/n");
                    if (userTemp == "y")
                    {
                        //takes user back to the reservation menu
                        Console.Clear();
                        CampGroundMenu(campGroundDictionary);
                    }
                    else if (userTemp == "n")
                    {
                        Console.Clear();
                        MainMenu();
                    }
                } while (userTemp != "y" || userTemp != "n");
            }


            foreach (KeyValuePair <int, CampSite> kvp in reservationDictionary)
            {
                Console.Write("{1, -10}", kvp.Key, kvp.Value.SiteNumber);
                Console.Write("{1, -11}", kvp.Key, kvp.Value.MaxOccupancy);
                Console.Write("{1, -14}", kvp.Key, kvp.Value.Accessiblity);
                Console.Write("{1, -18}", kvp.Key, kvp.Value.MaxRevLength);
                Console.Write("{1, -10}", kvp.Key, kvp.Value.Utilities);
                int totalDays = (int)(departureDate - arrivalDate).TotalDays;
                if (totalDays < 1)
                {
                    totalDays = 1;
                }
                decimal feeTotal = campGroundDictionary[campgroundChoice].Fee * totalDays;
                Console.Write($"{feeTotal:C}".PadLeft(10));
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine();
            int siteChoice = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)? ");

            if (siteChoice == 0)
            {
                CampGroundMenu(campGroundDictionary);
            }
            //prompts user for the name they want the reservation under
            string reservationName = CLIHelper.GetString("What name should the reservation be under? ");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine($"The reservation has been made and the confirmation id is {reservations.AddReservation(siteChoice, arrivalDate, departureDate, reservationName)})");
            Console.ReadLine();

            string temp = "";

            do
            {
                Console.Clear();
                temp = CLIHelper.GetString(
                    "Would you like to make another reservation? y/n");
                if (temp == "y")
                {
                    Console.Clear();
                    CampGroundMenu(campGroundDictionary);
                }
                else if (temp == "n")
                {
                    Console.Clear();
                    MainMenu();
                }
            } while (temp != "y" || temp != "n");
        }
    }