Example #1
0
        public void GetAvailableSites_Test(int campgroundId, string fromDate, string toDate, int expectedCount)
        {
            //Arrange
            SiteDAL dal = new SiteDAL(ConnectionString);

            //Act
            var sites = dal.GetAvailableSites(campgroundId, Convert.ToDateTime(fromDate), Convert.ToDateTime(toDate));

            //Assert
            Assert.AreEqual(expectedCount, sites.Count);
        }
Example #2
0
        public void GetAvailableSitesTest()
        {
            SiteDAL siteDAL = new SiteDAL(connectionString);

            arriveDate = Convert.ToDateTime("12/17/2017");
            departDate = Convert.ToDateTime("12/18/2017");

            List <Site> sites = siteDAL.GetAvailableSites(cgID, arriveDate, departDate);

            Assert.AreEqual(1, sites.Count);

            //arriveDate = Convert.ToDateTime("12-16-2017");
            //departDate = Convert.ToDateTime("12-19-2017");

            //List<Site> siteTest2 = siteDAL.GetAvailableSites(cgID, arriveDate, departDate);

            //Assert.AreEqual(0, siteTest2.Count);
        }
Example #3
0
        public bool AvailableForReservation(decimal dailyFee, int cgID, DateTime arriveDate, DateTime departDate)
        {
            SiteDAL siteDAL = new SiteDAL(connectionString);

            List <Site> availableSites = siteDAL.GetAvailableSites(cgID, arriveDate, departDate);

            if (availableSites.Count > 0)
            {
                int pad = 20;
                Console.WriteLine(" Results Matching Your Search Criteria");
                Console.WriteLine();
                Console.WriteLine(" Site#.".PadRight(pad) + "Max Occup.".PadRight(pad) + "Accessible?".PadRight(pad) + "Max RV Length".PadRight(pad) + "Utility".PadRight(pad) + "Cost");
                Console.WriteLine(" *".PadRight(120, '*'));

                foreach (Site a in availableSites)
                {
                    decimal cost = dailyFee * (decimal)((departDate - arriveDate).TotalDays);
                    Console.WriteLine(" " + Convert.ToString(a.SiteNum).PadRight(pad) + Convert.ToString(a.MaxOccupancy).PadRight(pad) + a.Accessible.PadRight(pad) + a.MaxRVLength.PadRight(pad) + a.Utilities.PadRight(pad) + "$" + cost.ToString("F2"));
                }
            }

            else
            {
                Console.WriteLine(" There are no campsites available for the dates you have selected. Would you like to try different dates? Y/N");
                string input = Console.ReadLine();
                if (input.ToLower() == "y")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            int siteNumSelection = 0;

            Console.WriteLine();
            Console.WriteLine(" Which site should be reserved (enter 0 to cancel)? __");

            try
            {
                siteNumSelection = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine(" Please enter valid option. Press any key to return.");
                Console.ReadKey();
                return(true);
            }

            bool siteExists = false;

            foreach (Site site in availableSites)
            {
                if (siteNumSelection == site.SiteNum)
                {
                    siteExists = true;
                }
            }

            if (siteNumSelection == 0)
            {
                return(false);
            }
            else if (siteExists == true)
            {
                Console.WriteLine(" What name should the reservation be made under? __");
                string reservationName = Console.ReadLine();
                MakeReservation(siteNumSelection, reservationName, arriveDate, departDate);
                Console.WriteLine(" Press any key to continue.");
                Console.WriteLine();
                Console.ReadKey();
                return(false);
            }
            else
            {
                Console.WriteLine(" Please enter a valid option. Press any key to return.");
                Console.ReadKey();
                return(true);
            }
        }
Example #4
0
        /// <summary>
        /// Builds List of sites from input
        /// </summary>
        /// <param name="parkId"></param>
        public bool PromptUserForDateRange(int parkId)
        {
            bool reservationMade = false;

            while (true)
            {
                //connects campgrounds database
                CampgroundDAL dal = new CampgroundDAL(DatabaseConnection);
                Console.Clear();

                //Builds Dictionary to show campgrounds per park
                IDictionary <int, Campground> campground = dal.GetAllCampgroundsPerPark(parkId);
                Console.WriteLine(" ".PadRight(5) + "Name".PadRight(35) + "Open".PadRight(10) + "Close".PadRight(13) + "Daily Fee".PadRight(10));
                foreach (KeyValuePair <int, Campground> camps in campground)
                {
                    Console.WriteLine("#" + camps.Key.ToString().PadRight(4) +
                                      camps.Value.Name.ToString().PadRight(35) +
                                      camps.Value.OpenFrom.ToString().PadRight(10) +
                                      camps.Value.OpenTo.ToString().PadRight(13) +
                                      camps.Value.DailyFee.ToString("c").ToString().PadRight(10));
                }
                Console.Write("Which campground (enter 0 to cancel)? ");
                string campgroundChoice = Console.ReadLine();
                int    campSelection;

                bool campKey = int.TryParse(campgroundChoice, out campSelection);
                if (campKey == false)
                {
                    Console.WriteLine("Please enter a valid selection.");
                    Thread.Sleep(2000);
                }
                else if (campground.ContainsKey(campSelection))
                {
                    int campId = campground[campSelection].Id;
                    //Holds input variables
                    DateTime fromDate, toDate;
                    // Calls method to choose dates
                    ChooseACampground(out fromDate, out toDate);

                    //Calls DAL to build a dictionary of sites available for specified date range
                    SiteDAL siteDal = new SiteDAL(DatabaseConnection);
                    try
                    {
                        IDictionary <int, Site> AvailableSites = siteDal.GetAvailableSites(campId, fromDate, toDate);
                        //if there are no available sites ask them for an alternate date range
                        if (AvailableSites.Count == 0)
                        {
                            Console.WriteLine("There are no available sites.");
                            Console.Write("Would you like to select another date range? Y or N ");
                            string selection = Console.ReadLine();
                            if (selection.ToLower() == "y")
                            {
                                ChooseACampground(out fromDate, out toDate);
                            }

                            //Quit or Return to main menu
                            if (selection.ToLower() == "n")
                            {
                                break;
                            }
                            else
                            {
                                Console.Write("Please enter a valid selection");
                            }
                        }

                        //Shows campground selection
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine("Results matching your search criteria");
                            Console.WriteLine("Site No.".PadRight(10) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(15) + "Utility".PadRight(15) + "Cost".PadRight(15));
                            foreach (KeyValuePair <int, Site> site in AvailableSites)
                            {
                                Console.WriteLine(site.Value.SiteNumber.ToString().PadRight(10) +
                                                  site.Value.MaxOccupancy.ToString().PadRight(15) +
                                                  (site.Value.Accessible ? "Yes" : "No").PadRight(15) +
                                                  ((site.Value.MaxRv == 0) ? "N/A" : site.Value.MaxRv.ToString()).PadRight(15) +
                                                  (site.Value.Utilities ? "Yes" : "No").PadRight(15) +
                                                  (TotalDays(fromDate, toDate) * site.Value.DailyFee).ToString().PadRight(15));
                            }

                            //To Reserve a site
                            Console.WriteLine("Which site should be reserved(enter 0 to cancel)? ");
                            int siteToReserve = int.Parse(Console.ReadLine());
                            if (siteToReserve == 0)
                            {
                                break;
                            }
                            if (AvailableSites.ContainsKey(siteToReserve))
                            {
                                Console.WriteLine("What name should the reservation be made under ?");
                                string         reservationName = Console.ReadLine();
                                ReservationDAL reservationdDal = new ReservationDAL(DatabaseConnection);
                                int            reservationId   = reservationdDal.MakeAReservation(siteToReserve, fromDate, toDate, reservationName);
                                Console.WriteLine("The reservation has been made");
                                Console.WriteLine($"The confirmation ID is : {reservationId}");
                                Console.WriteLine($"Press Enter to Return to Park List");
                                Console.ReadLine();
                                return(reservationMade = true);
                            }
                            else
                            {
                                Console.Write("Please enter a valid selection");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("The input is not valid");
                        break;
                    }
                }
                else if (campSelection == 0)
                {
                    break;
                }
            }
            return(reservationMade);
        }