public void BookReservation(Reservation r) { string name = CLIHelper.GetString("Please enter first and last name:"); int siteNumber = CLIHelper.GetInteger("Please enter the site number: "); int numberCampers = CLIHelper.GetInteger("Please enter the number of campers:"); int reservationID = 0; r.Name = name; r.SiteNumber = siteNumber; r.NumberCampers = numberCampers; ReservationSqlDAL dal = new ReservationSqlDAL(); try { reservationID = dal.BookReservation(r); } catch (Exception e) { Console.WriteLine(e.Message); } if (reservationID > 0) { Console.WriteLine($"Your reservation was successfully created. Reservation id: {reservationID}"); } else { Console.WriteLine("Request unsuccessful. Reservation NOT created."); } }
/// <summary> /// Displays available campsites within a campground based on the user's selection and options /// </summary> /// <param name="campId"></param> /// <param name="arriveDate"></param> /// <param name="departDate"></param> public void DisplayAvailableSites(int campId, DateTime arriveDate, DateTime departDate) { SiteSqlDAL siteDal = new SiteSqlDAL(DatabaseConnection); List <Site> sites = siteDal.GetCampgroundSites(campId, arriveDate, departDate); bool timeToExit = false; while (!timeToExit) { if (sites.Count == 0) { Console.WriteLine("There are no available sites on that date, try again."); Console.ReadKey(); Console.Clear(); Header(); timeToExit = true; //CampgroundReservation(_parks[campId]); } else { int numDays = (int)(departDate - arriveDate).TotalDays + 1; decimal totalCost = _campgrounds[campId - 1].CalculateCost(_campgrounds[campId - 1], numDays); Console.Clear(); Header(); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine(); Console.WriteLine($"{siteNo,6} | {maxOcc,9} | {access,9} | {rvLngth,9} | {utility,9} | {cost,9}"); for (int i = 0; i < sites.Count; i++) { Console.WriteLine($"{sites[i].SiteNumber,8} | {sites[i].MaxOccupancy,10} | {sites[i].Accessible,11} | {sites[i].MaxRvLength,13} | {sites[i].Utilities,9} | {totalCost.ToString("c"),9}"); } //iterates through the Sites List to display to user Console.WriteLine(); int siteId = CLIHelper.GetInteger("Which site would you like to reserve ? (enter 0 to cancel)"); if (siteId == 0) { Console.Clear(); Header(); timeToExit = true; } Console.WriteLine(); string resName = CLIHelper.GetString("What name should your reservation be called?"); ReservationSqlDAL sqlDal = new ReservationSqlDAL(DatabaseConnection); int resConfirmationId = sqlDal.BookReservation(siteId, arriveDate, departDate, resName); Console.WriteLine(); Console.WriteLine($"The reservation has been made and your confirmation number is {resConfirmationId}"); Console.WriteLine("Click any key to exit the program."); timeToExit = true; Console.ReadKey(); } } }
public void BookReservationTest() { Reservation r = new Reservation() { Name = "Mitchel Mayle", CampgroundName = "Blackwoods", CreateDate = Convert.ToDateTime("2017-01-01"), NumberCampers = 1, FromDate = Convert.ToDateTime("2017-01-01"), ToDate = Convert.ToDateTime("2017-01-02"), SiteId = 1, SiteNumber = 1 }; ReservationSqlDAL dal = new ReservationSqlDAL(); int resNum = dal.BookReservation(r); }
public void ReservationSqlDALTestsBookReservation() { using (TransactionScope transaction = new TransactionScope()) { //Arrange SiteSqlDALTests tests = new SiteSqlDALTests(); int siteId = tests.InsertFakeSite(); int id = InsertFakeReservation("Random", siteId); ReservationSqlDAL testClass = new ReservationSqlDAL(connectionString); //Act int finalId = testClass.BookReservation(siteId, "Random", DateTime.Now, DateTime.Now); //Assert Assert.AreEqual(id, finalId - 1); } }
public void BookReservation() { string name = CLIHelper.GetString("Please enter first and last name:"); string campgroundName = CLIHelper.GetString("Please enter the campground name:"); int siteNumber = CLIHelper.GetInteger("Please enter the site number: "); int numberCampers = CLIHelper.GetInteger("Please enter the number of campers:"); DateTime startDate = CLIHelper.GetDateTime("Please enter a start date:"); DateTime endDate = CLIHelper.GetDateTime("Please enter an end date:"); int reservationID = 0; Reservation r = new Reservation() { Name = name, FromDate = startDate, ToDate = endDate, SiteNumber = siteNumber, NumberCampers = numberCampers, CampgroundName = campgroundName }; ReservationSqlDAL dal = new ReservationSqlDAL(); try { reservationID = dal.BookReservation(r); } catch (Exception e) { Console.WriteLine(e.Message); } if (reservationID > 0) { Console.WriteLine($"Your reservation was successfully created. Reservation id: {reservationID}"); } else { Console.WriteLine("Request unsuccessful. Reservation NOT created."); } }
private void DisplaySitesMatchingSearchCriteriaSelectMenu(string campId, DateTime arrivalDate, DateTime departureDate) // Add datetimes for arrival and departure? { while (true) { SiteSqlDAL dal = new SiteSqlDAL(connectionString); SiteSqlDAL dal2 = new SiteSqlDAL(connectionString); List <Site> sites = dal.GetAllAvailableCampsites(campId, arrivalDate, departureDate); PrintHeader(); string accessible; string utility; int confirmationID = -1; Console.Clear(); if (sites.Count > 0) { Console.WriteLine(("Site No.").PadRight(12) + ("Max Occup.").PadRight(12) + ("Accessible?").PadRight(20) + ("Max RV Length").PadRight(20) + ("Utility").PadRight(12) + ("Cost of Stay").PadRight(12)); foreach (Site site in sites) { TimeSpan timeSpan = departureDate.Subtract(arrivalDate); int totalDays = (int)timeSpan.TotalDays; decimal cost = totalDays * site.Daily_Fee; if (site.Campground_Id.ToString() == campId) { if (site.Accessible) { accessible = "Yes"; } else { accessible = "No"; } if (site.Utilities) { utility = "Yes"; } else { utility = "N/A"; } Console.WriteLine(site.Site_Number.ToString().PadRight(12) + site.Max_Occupancy.ToString().PadRight(12) + accessible.PadRight(20) + site.Max_Rv_Length.ToString().PadRight(20) + utility.PadRight(12) + cost.ToString("C").PadRight(12)); } } Console.WriteLine(); Console.Write("Which site should be reserved (enter 0 to cancel)? "); string userInputSiteId = Console.ReadLine(); if (userInputSiteId == "0") { Console.Clear(); break; } Console.Write("What name should the reservation be made under?"); string userInputName = Console.ReadLine(); ReservationSqlDAL dalRes = new ReservationSqlDAL(connectionString); foreach (Site site in sites) { if (userInputSiteId == site.Site_Number.ToString()) { confirmationID = dalRes.BookReservation(site.Site_Id, userInputName, arrivalDate, departureDate); Console.WriteLine(); Console.WriteLine($"The Reservation has been made for {userInputName} and the Confirmation ID# is {confirmationID}"); Freeze(); break; } else { Console.WriteLine(); Console.WriteLine("You entered an invalid ID"); Freeze(); } } Console.Write("Enter any key to add another reservation or Enter (X) to EXIT "); char userInput = Console.ReadKey(false).KeyChar; if (userInput.ToString().ToLower() == "x") { Console.WriteLine(); Environment.Exit(0); } } else { Console.WriteLine("****THERE ARE CURRENTLY NO AVAILABLE CAMPSITES IN THAT CAMPGROUND IN THAT TIME PERIOD****"); Freeze(); break; } } }
private void DisplayReservationMenu(Park park) { bool exit = false; while (!exit) { Console.Clear(); Console.WriteLine(); Console.WriteLine("Search for Campground Reservation"); Console.WriteLine(); Console.WriteLine(string.Format("{0, -4}{1, -20}{2, -20}{3, -20}{4, -20}", "", "Name", "Open", "Close", "Daily Fee")); DisplayCampgrounds(park); Console.WriteLine(); int campgroundId = CLIHelper.GetInteger("Choose a campground ? (enter 0 to cancel)"); if (campgroundId == 0) { exit = true; } else { while (!exit) { _arrivalDate = CLIHelper.GetDate("What is the arrival date? (MM/DD/YYYY)"); exit = ValidateArrivalDate(_arrivalDate); } exit = false; while (!exit) { _departureDate = CLIHelper.GetDate("What is the departure date? (MM/DD/YYYY)"); exit = ValidateDepartureDate(_departureDate); } exit = false; int numDays = (int)(_departureDate - _arrivalDate).TotalDays + 1; decimal totalCost = CalculateCost(campgroundId, numDays); while (!exit) { Console.WriteLine(); Console.WriteLine(string.Format("{0, -10}{1, -22}{2, -20}{3, -20}{4, -20}{5, -20}", "Site No.", "Max Occup.", "Max RV Length", "Accessible?", "Utilities", "Cost")); DisplayCampgroundSites(campgroundId, _arrivalDate, _departureDate); Console.WriteLine(); int inputNum = CLIHelper.GetInteger("Which site should be reserved? (Enter 0 to cancel)"); if (inputNum == 0) { exit = true; } else { //Console.WriteLine("What name should the reservation be made under?"); //string resName = Console.ReadLine(); string resName = CLIHelper.GetString("What name should the reservation be made under?"); int confirmNum = _reservationDAL.BookReservation(inputNum, _arrivalDate, _departureDate, resName); Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"The reservation has been made and the confirmation number is {confirmNum}"); Console.ReadKey(); Environment.Exit(0); } } } } }
public void ReservationMenu(int parkId) { Console.WriteLine("Select an Option: "); Console.WriteLine("1) Search for Available Reservation "); Console.WriteLine("2) Return to Previous Screen "); string input = Console.ReadLine(); if (input == "1") { //CampGroundMenu(parkId); // Prompt&Get for campgroundID: campgroundId Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Which campground (enter 0 to cancel)? "); string inputCG = Console.ReadLine(); if (inputCG == "0") { Console.WriteLine(); ReservationMenu(parkId); } // Prompt&Get for arrive date: fromDate Console.WriteLine("What is the arrival date (mm/dd/yyyy)? "); string inputFD = Console.ReadLine(); // Prompt&Get for depart date: toDate Console.WriteLine("What is the departure date (mm/dd/yyyy)? "); string inputTD = Console.ReadLine(); int campGroundId = int.Parse(inputCG); DateTime fromDate = DateTime.Parse(inputFD); DateTime toDate = DateTime.Parse(inputTD); ISiteDAL siteDal = new SiteSqlDAL(DatabaseConnection); IList <Site> sites = siteDal.GetAvailableSite(campGroundId, fromDate, toDate); ICampGroundDAL cgDal = new CampGroundSqlDAL(DatabaseConnection); IList <CampGround> campGrounds = cgDal.GetCampGroundByPark(parkId); double totalDays = (toDate - fromDate).TotalDays; if (sites.Count <= 0) { Console.WriteLine("No available campsites, please enter an alternate DateRange. "); } else if (sites.Count > 0 && sites.Count < 8) { Console.Clear(); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(" Site No.".PadRight(20) + "Max Occup.".PadRight(20) + "Accessible?".PadRight(20) + "RV Len".PadRight(10) + "Utility".PadRight(10) + "Cost"); int choice = 1; foreach (Site site in sites) { // Added ToString() to limit cost value to two decimal places Console.WriteLine(choice + ")" + " " + site.SiteNumber.ToString().PadRight(20) + site.MaxOccupancy.ToString().PadRight(20) + site.IsAccessible.ToString().PadRight(20) + site.MaxRvLength.ToString().PadRight(10) + site.Utilities.ToString().PadRight(10) + "$" + (campGrounds[campGroundId - 1].DailyFee * (decimal)totalDays).ToString("0.00")); choice++; } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Which site should be reserved (enter 0 to cancel)?"); string inputSite = Console.ReadLine(); Console.WriteLine("What name should the reservation be made under?"); string inputName = Console.ReadLine(); Reservation reservation = new Reservation() { Name = inputName, SiteId = int.Parse(inputSite), FromDate = fromDate, ToDate = toDate, BookDate = DateTime.Now }; IReservationDAL resDal = new ReservationSqlDAL(DatabaseConnection); IList <Reservation> reservations = resDal.BookReservation(reservation); Console.WriteLine(); Console.WriteLine($"The reservation has been made and the Confirmation ID is {reservation.ReservationId}"); } } else if (input == "2") { Console.Clear(); IParkDAL parkDal = new ParkSqlDAL(DatabaseConnection); ICampGroundDAL cgDal = new CampGroundSqlDAL(DatabaseConnection); Park park = parkDal.GetParkById(parkId); IList <CampGround> campGrounds = cgDal.GetCampGroundByPark(parkId); if (campGrounds.Count > 0) { Console.WriteLine(park.Name + " " + "National Park Campgrounds"); Console.WriteLine(); Console.WriteLine("Campgound Id".PadRight(21) + "Name".PadRight(40) + "Open".PadRight(20) + "Close".PadRight(20) + "Daily Fee"); foreach (CampGround campGround in campGrounds) { Console.WriteLine("#" + campGround.CampGroundId.ToString().PadRight(20) + campGround.Name.ToString().PadRight(40) + GetMonthString(campGround.OpenFrom).ToString().PadRight(20) + GetMonthString(campGround.OpenTo).ToString().PadRight(20) + "$" + campGround.DailyFee.ToString("0.00")); } } Console.WriteLine(); CampGroundMenu(parkId); } }