Exemplo n.º 1
0
        //GET: Confirmation
        public ActionResult Confirmation(Reservation reservation)
        {
            ReservationSqlDAL reservationDAL = new ReservationSqlDAL(connectionString);

            int reservationId = reservationDAL.CreateReservation(reservation.SiteID, reservation.ReservationStart, reservation.ReservationEnd, reservation.ReservationName);

            return(View("Confirmation", reservationId));
        }
        public void CreateReservationTest()
        {
            //Arrange
            ReservationSqlDAL reservationSqlDal = new ReservationSqlDAL(connectionString);

            //Act
            int reservation = reservationSqlDal.CreateReservation(3, today, today, "Test");

            //Assert
            Assert.IsNotNull(reservation);
            Assert.AreEqual(reservation, reservationNumber + 1);
        }
        public void CreateReservationTest()
        {
            ReservationSqlDAL reservationDAL = new ReservationSqlDAL(connectionString);
            int reservationId = reservationDAL.CreateReservation(1, "TestName", new DateTime(1990, 08, 28), new DateTime(1990, 09, 14));

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                //SqlCommand command;
                conn.Open();

                //command = new SqlCommand("INSERT INTO reservation VALUES (1, TestName, '08/28/1990', '09/14/1990', GETDATE(); SELECT CAST (SCOPE_IDENTITY() AS int)", conn);
                SqlCommand command = new SqlCommand("SELECT * FROM reservation WHERE name = 'TestName'; SELECT CAST(SCOPE_IDENTITY() AS int)", conn);
                reservationIdColumn = (int)command.ExecuteScalar();
            }
            Assert.AreEqual(reservationId, reservationIdColumn);

            // Assert.IsTrue(true);
        }
        // method that inserts a reservation //
        private List <Site> MakeReservation(Campground campground, DateTime arrival, DateTime departure)
        {
            // opens a connection to provide a list of sites for current campground //
            SiteSqlDAL  dal   = new SiteSqlDAL(connectionString);
            List <Site> sites = dal.GetAvailableSites(campground, arrival, departure);
            // customer chooses which site they'd like to make a reservation for OR cancels //
            int customerSelection = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?");

            // customer chose to return to main menu (probably choked on total cost of trip) //
            if (customerSelection == 0)
            {
                Console.Clear();
                ParksInterface mainmenu = new ParksInterface();
                mainmenu.RunCLI();
            }
            else if (customerSelection > sites.Count)
            {
                Console.WriteLine("That site does not exist, returning to main menu!");
                Thread.Sleep(milliseconds);
                Console.Clear();
                ParksInterface mainmenu = new ParksInterface();
                mainmenu.RunCLI();
            }
            // customer opted to make a reservation //
            // returns a list of all current resos, then gives customer confirmation number using last reservation_id (newest created) //
            else
            {
                string             reservationName = CLIHelper.GetString("What name should the reservation be made under?");
                int                selectedSite    = customerSelection - 1;
                DateTime           now             = DateTime.Now;
                ReservationSqlDAL  resodal         = new ReservationSqlDAL(connectionString);
                List <Reservation> result          = resodal.CreateReservation(sites[selectedSite].site_id, reservationName, arrival, departure, now);
                Console.WriteLine($"The reservation has been made and the confirmation id is {result[result.Count - 1].reservation_id.ToString()}");
            }
            return(sites);
        }
        private int BookReservation(Reservation reservation)
        {
            ReservationSqlDAL reservationDal = new ReservationSqlDAL(connectionString);

            return(reservationDal.CreateReservation(reservation));
        }
Exemplo n.º 6
0
        public void CampGroundChoices(List <Campground> campgrounds)
        {
            Console.WriteLine("Select a campground to check for availability. Please select a number");

            for (int i = 0; i < campgrounds.Count; i++)
            {
                Console.WriteLine((i + 1).ToString().PadRight(10) + campgrounds[i].Name);
            }

            int parsedUserInput = 0;

            while (parsedUserInput <= 0 || parsedUserInput > campgrounds.Count)
            {
                string userInput = Console.ReadLine();
                Int32.TryParse(userInput, out parsedUserInput);
                if (parsedUserInput <= 0 || parsedUserInput > campgrounds.Count)
                {
                    Console.WriteLine("Please enter a valid number");
                }
            }

            Campground userCampground = campgrounds[parsedUserInput - 1];

            Console.WriteLine("You Selected campground " + userCampground.Name);
            Console.WriteLine();

            DateTime startDate = DateTime.MinValue;

            while (startDate < DateTime.Today)
            {
                Console.WriteLine("Please enter a valid start date (MM/DD/YYYY)");
                Console.WriteLine();
                string userStartDate = Console.ReadLine();
                DateTime.TryParse(userStartDate, out startDate);
            }

            Console.WriteLine("Your start date is " + startDate.ToShortDateString());
            Console.WriteLine();

            DateTime endDate = DateTime.MinValue;

            while (endDate < startDate)
            {
                Console.WriteLine("Please enter a valid end date (MM/DD/YYYY)");
                Console.WriteLine();
                string userEndDate = Console.ReadLine();
                DateTime.TryParse(userEndDate, out endDate);
            }

            Console.WriteLine("Your end date is " + endDate.ToShortDateString());
            Console.WriteLine();

            IReservationDAL    dal             = new ReservationSqlDAL(databaseConnection);
            List <int>         numberOfSites   = dal.GetTotalSites(userCampground.CampgroundId);
            List <Reservation> allReservations = dal.GetAllReservations();
            List <int>         openSites       = dal.IsReservationOpen(startDate, endDate, allReservations, numberOfSites);

            bool isOpen = dal.IsCampgroundOpen(userCampground, startDate, endDate);

            if (isOpen)
            {
                IReservationDAL reservation = new ReservationSqlDAL(databaseConnection);

                ISiteDAL    siteDAL        = new SiteSqlDAL(databaseConnection);
                List <Site> availableSites = siteDAL.GetAvailableSites(userCampground.CampgroundId);

                Console.WriteLine("Available Camp Sites:");
                foreach (Site camp in availableSites)
                {
                    if (numberOfSites.Contains(camp.SiteId))
                    {
                        Console.WriteLine("Site ID: " + camp.SiteId);
                        Console.WriteLine("Site #" + camp.SiteNumber);
                        Console.WriteLine(" Max Occupancy: " + camp.MaxOccupancy);
                        Console.WriteLine(" Handicap Accessible: " + camp.yesOrNo(camp.Accessible));
                        Console.WriteLine(" Max RV Length: " + camp.RvLength.ToString());
                        Console.WriteLine(" Utilities Available: " + camp.yesOrNo(camp.HasUtilities));
                        Console.WriteLine(" Total Fee: " + (userCampground.DailyFee * Convert.ToInt32((endDate.Subtract(startDate)).TotalDays)).ToString("C2"));
                        Console.WriteLine();
                    }
                    else if (numberOfSites.Count == 0)
                    {
                        Console.WriteLine("Sorry, no camp sites are available during that time.");
                    }
                }
            }
            else
            {
                Console.WriteLine("The campground is not open during that period");
            }

            bool userInputId = false;

            while (userInputId == false)
            {
                Console.WriteLine("Please enter the Site ID for your desired site:");
                string response = Console.ReadLine();
                int    userSite = 0;
                if (int.TryParse(response, out int result))
                {
                    userSite = int.Parse(response);
                }

                if (numberOfSites.Contains(userSite))
                {
                    userReservation.SiteId = userSite;
                    userInputId            = true;
                }
                else
                {
                    Console.WriteLine("That was not a valid site number");
                }
            }
            Console.WriteLine("What name would you like to book this reservation under? ");
            string userName = Console.ReadLine();

            userReservation.Name        = userName;
            userReservation.From_Date   = startDate;
            userReservation.To_Date     = endDate;
            userReservation.Create_Date = DateTime.Now;

            bool reservationSuccess = dal.CreateReservation(userReservation);

            if (reservationSuccess)
            {
                IReservationDAL    dalUpdated          = new ReservationSqlDAL(databaseConnection);
                List <Reservation> updatedReservations = dalUpdated.GetAllReservations();

                Console.WriteLine("Your reservation has been successfully booked!");

                Console.WriteLine("Your confirmation id is " + (updatedReservations.Count));
            }
        }