public void GetSitesTest() { SiteDAL dal = new SiteDAL(connectionString); List <Site> sites = dal.GetSites(campgroundId); Assert.AreEqual(1, sites.Count); Assert.AreEqual(500, sites[0].MaxRVLength); }
public void GetSites() { //Arrange SiteDAL siteDAL = new SiteDAL(_connectionString); //Act List <Site> sites = siteDAL.GetSites(campground); //Assert Assert.AreEqual(1, sites.Count); Assert.AreEqual(_siteId, sites[0].SiteId); }
public void GetSites(int campgroundId, int expectedOutput) { // Arrange SiteDAL site = new SiteDAL(ConnectionString); // Act var listOfSites = site.GetSites(new Campground() { CampgroundId = campgroundId }); // Assert Assert.AreEqual(expectedOutput, listOfSites.Count); }
private void MakeReservationCLI(Campground campground, int siteID, DateTime userArrivalDate, DateTime userDepartureDate) { string reservationName = CLIHelper.GetString("What name should the reservation be made under?"); Site chosenSite = new Site(); ReservationDAL reservationDAL = new ReservationDAL(DatabaseConnection); Reservation finalReservation = new Reservation() { SiteId = siteID, Name = reservationName, FromDate = userArrivalDate, ToDate = userDepartureDate, CreateDate = DateTime.Now }; bool noExceptions = true; try { reservationDAL.MakeReservation(finalReservation); } catch (Exception e) { noExceptions = false; Console.WriteLine(e.Message); Console.WriteLine("Press Any Key to Return to Park Menu"); Console.ReadKey(); } if (noExceptions) { SiteDAL siteDAL2 = new SiteDAL(DatabaseConnection); List <Site> allSites = siteDAL2.GetSites(campground); Dictionary <int, Site> siteDictionaryForCampground = new Dictionary <int, Site>(); foreach (Site item in allSites) { siteDictionaryForCampground.Add(item.SiteId, item); } chosenSite = siteDictionaryForCampground[finalReservation.SiteId]; List <Reservation> allReservations = reservationDAL.GetCurrentReservations(chosenSite); Console.WriteLine($"Reservation Booked! Your Confirmation Number is {allReservations[0].ReservationId}"); Console.WriteLine(); Console.WriteLine("Press any Key to return to menu"); Console.ReadKey(); } }
private void ReservationAvailable(int campground, DateTime start, DateTime end) { SiteDAL dal = new SiteDAL(databaseConnection); CampgroundDAL dal2 = new CampgroundDAL(databaseConnection); Campground campgroundObject = dal2.GetCampgroundById(campground); List <Reservation> reservations = dal.GetReservation(campground); //List<Reservation> booked = new List<Reservation>(); List <Site> sites = dal.GetSites(campground); List <Reservation> available = new List <Reservation>(); Console.WriteLine("Site Id | Max Occupancy | Accessible | Max RV Size | Utilities | Daily Fee"); reservations.ForEach(res => { bool overlap = (end >= res.StartDate && end <= res.EndDate) || (start >= res.StartDate && start <= res.EndDate) || (start <= res.StartDate && end >= res.EndDate); //bool overlap = (res.StartDate <= end && start <= res.EndDate) || // (start <= res.StartDate && res.StartDate <= end) || // (start <= res.EndDate && res.EndDate <= end) || // (res.StartDate <= start && res.EndDate >= end); if (overlap) { sites.Remove(sites.Find(s => s.Id == res.SiteId)); } }); if (sites.Count == 0) { Console.WriteLine("I am sorry, there are no reservations available during your specified date range. Please try again."); } sites.ForEach(availableSite => { Console.WriteLine($"{availableSite.Id} {availableSite.MaxOccupancy} {availableSite.isAccessible} {availableSite.MaxRVLength} {availableSite.hasUtilities} {campgroundObject.DailyFee}"); }); }
public void ReservationDisplay(Park park) { bool exit = false; while (!exit) { Console.Clear(); CampgroundsDAL campgrounds = new CampgroundsDAL(_connectionString); List <CampGround> cgList = new List <CampGround>(); cgList = campgrounds.GetCampGrounds(park); Dictionary <int, CampGround> cgDictionary = new Dictionary <int, CampGround>(); Console.WriteLine("------------------------------------------------------------------------------------------------"); Console.WriteLine(" Park Campgrounds "); Console.WriteLine($" {park.Name} "); Console.WriteLine("------------------------------------------------------------------------------------------------"); Console.WriteLine(String.Format("{0, -5} {1,-32} | {2,-15} | {3,-15} | {4,-15}", " ", "Name", "Open", "Close", "Daily Fee")); CampGround campground = new CampGround(); for (int i = 1; i <= cgList.Count; i++) { campground = cgList[i - 1]; Console.WriteLine(String.Format("{0, -5} {1,-32} | {2,-15} | {3,-15} | {4,-15}", $"#{i}", campground.Name, campground.OpenMonth, campground.CloseMonth, campground.DailyFee.ToString("c"))); cgDictionary.Add(i, campground); } Console.WriteLine(); Console.WriteLine("Which campground (enter 0 to cancel)?"); string selCampground = Console.ReadLine(); if (selCampground == "0") { exit = true; } else { Console.WriteLine(); ReservationDAL reservations = new ReservationDAL(_connectionString); Reservation reservation = new Reservation(); // try catch Console.WriteLine("What is the arrival date? (mm/dd/yyyy)"); DateTime arrivalDate = Convert.ToDateTime(Console.ReadLine()); reservation.FromDate = arrivalDate; Console.WriteLine("What is the departure date? (mm/dd/yyyy)"); DateTime departureDate = Convert.ToDateTime(Console.ReadLine()); reservation.ToDate = departureDate; //CampGround campground = new CampGround(); int cgId = cgDictionary[int.Parse(selCampground)].CampgroundId; CampGround camp = cgDictionary[int.Parse(selCampground)]; arrivalDate = Convert.ToDateTime(arrivalDate); departureDate = Convert.ToDateTime(departureDate); //List<Reservation> resList = new List<Reservation>(); var resList = reservations.SearchReservations(reservation); bool toExit = false; while (!toExit) { bool isAvailable = (resList.Count != 0); if (isAvailable) { Console.Clear(); Console.WriteLine("Results Matching Your Search Criteria: "); Console.WriteLine(); Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,-18} | {3,-15} | {4,-15} | {5,-15}", "Site No.", "Max Occup.", "Accessible?", "Max RV Length", "Utility", "Cost")); TimeSpan totalTime = departureDate - arrivalDate; int totalDays = totalTime.Days; Site site = new Site(); SiteDAL sites = new SiteDAL(_connectionString); List <Site> siteList = new List <Site>(); siteList = sites.GetSites(camp); Dictionary <int, Site> siteDictionary = new Dictionary <int, Site>(); //double totalCost = campground.DailyFee * totalDays; for (int i = 1; i <= siteList.Count; i++) { site = siteList[i - 1]; Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,-18} | {3,-15} | {4,-15} | {5,-15}", site.SiteNumber, site.MaxOccupancy, site.Accessible, site.MaxRvLength, site.Utilities, (campground.DailyFee * totalDays).ToString("c"))); siteDictionary.Add(i, site); } Console.WriteLine(); Console.WriteLine("Select a site to reserve: "); string selSite = Console.ReadLine(); site.SiteNumber = int.Parse(selSite); Console.WriteLine("Enter a name for the reservation: "); string resName = Console.ReadLine(); //reservations.CreateReservation(reservation); //reservation.Name = resName; //reservation.ToDate = arrivalDate; //reservation.FromDate = departureDate; reservations.CreateReservation(resName, arrivalDate, departureDate, site.SiteNumber); Random random = new Random(); int confirmNum = random.Next(000000000, 999999999); Console.WriteLine($"Reservation made. Your confirmation number is: {confirmNum}."); } else { Console.Clear(); Console.WriteLine("The campsite you have chosen is not available for those dates."); Console.WriteLine("(1) Select new dates"); Console.WriteLine("(2) Return to previous menu"); string selection = Console.ReadLine(); if (selection == "2") { toExit = true; } else { Console.ReadKey(); } } } // arrivalDate.CompareTo() // or create a SQL statement that where date is before date and date is after date } } }