public void MakeReservation(DateTime fromDate, DateTime toDate) { Console.WriteLine(); Console.WriteLine("Which site should be reserved (enter 0 to cancel)? __ "); int userInput = Convert.ToInt32(Console.ReadLine()); string reservationName = string.Empty; if (userInput == 0) { return; } else { Console.WriteLine("What name should the reservation be made under? __"); reservationName = Console.ReadLine(); Reservation newReservation = new Reservation() { SiteId = userInput, Name = reservationName, FromDate = fromDate, ToDate = toDate, CreateDate = DateTime.Now }; ReservationSqlDal dal = new ReservationSqlDal(dbConnection); bool rowInserted = dal.CreateReservation(newReservation); if (rowInserted) { int reservationId = dal.GetLastReservations(); Console.WriteLine("Reservation was successfully created and reservation id is " + reservationId); Console.ReadKey(); } } }
public void GetAllCurrentReservations(Dictionary <int, Park> listOfParks) { DisplayAllParks(listOfParks); Console.WriteLine(); Console.WriteLine("Please Select A Park_____"); int parkId = Convert.ToInt32(Console.ReadLine()); if (listOfParks.ContainsKey(parkId)) { ReservationSqlDal dal = new ReservationSqlDal(dbConnection); Dictionary <int, Reservation> dictReservations = dal.GetCurrentReservations(parkId); if (dictReservations.Count > 0) { Console.WriteLine("Current Park Reservations: "); Console.WriteLine("ID\t Site ID\t\t Reservation Name\t\t Start Date\t" + "End date\t Create Date"); foreach (var key in dictReservations.Keys) { Console.WriteLine(dictReservations[key].ToString()); } } else { Console.WriteLine("Sorry there are no current reservations. "); } Console.ReadKey(); } }
public void MakeReservationTest() { //Arrange ReservationSqlDal reservationSqlDal = new ReservationSqlDal(connectionString); int siteId = 1; string name = "Test Reservation"; DateTime checkInDate = new DateTime(2100, 1, 1); DateTime checkOutDate = new DateTime(2100, 1, 5); //Act int reservationId = reservationSqlDal.MakeReservation(siteId, name, checkInDate, checkOutDate); //Assert Assert.AreNotEqual(0, reservationId); }
public void MakeReservationPrompts(DateTime checkInDate, DateTime checkOutDate, List <Site> availableSites) { ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection); int siteToReserve = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?"); //quit if zero if (siteToReserve == 0) { Console.WriteLine("Cancelled! Press any key to continue."); return; } //check if non-zero response is actually available bool isValidSite = false; foreach (Site site in availableSites) { if (site.Id == siteToReserve) { isValidSite = true; } } //display message if site chosen was invalid if (!isValidSite) { Console.WriteLine("\nInvalid site or site not available, please try another campsite. \nPress any key to continue: "); } else { string reservationName = CLIHelper.GetString("What name should the reservation be made under?"); int confirmationId = reservationSqlDal.MakeReservation(siteToReserve, reservationName, checkInDate, checkOutDate); if (confirmationId != 0) { Console.WriteLine($"The reservation has been made and the confirmation id is {confirmationId}"); } else { Console.WriteLine($"Error: The reservation was not made"); } Console.WriteLine("\nPress any key to continue"); } Console.ReadKey(); return; }
public void SearchForReservationByIdScreen() { ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection); List <Reservation> reservations = reservationSqlDal.GetAllReservations(); Console.WriteLine("Reservation Search:\n"); int reservationId = CLIHelper.GetInteger("Please enter your reservation ID #:"); Reservation selectedReservation = GetReservationById(reservationId, reservations); if (selectedReservation != null) { Console.WriteLine($"Reservation {reservationId} found..."); Console.WriteLine(selectedReservation.ToString()); } else { Console.WriteLine("Reservation not found!"); } Console.WriteLine("Press any key to continue"); Console.ReadKey(); }
public void GetAllReservationsFromCampgroundTest() { //Arrange ReservationSqlDal reservationSqlDal = new ReservationSqlDal(connectionString); //Act List <Reservation> reservations = reservationSqlDal.GetAllReservationsFromCampground(1); //Assert Assert.IsNotNull(reservations, "Reservations list is empty!"); Assert.AreEqual(reservationInCampgroundCount, reservations.Count, $"Expected a count of {reservationInCampgroundCount} for reservations"); bool found = false; foreach (Reservation reservation in reservations) { if (reservation.Name == "Test Reservation") { found = true; break; } } Assert.IsTrue(found, "Could not find Test Reservation named Test Reservation"); }
public void SearchForAvailableReservationScreen(Park park) { SiteSqlDal siteSqlDal = new SiteSqlDal(DatabaseConnection); CampgroundSqlDal campgroundSqlDal = new CampgroundSqlDal(DatabaseConnection); ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection); List <Campground> campgrounds = campgroundSqlDal.GetAllCampgroundsFromPark(park.Id); //Search for valid campground bool done = false; while (!done) { Console.Clear(); Console.WriteLine("Search for Campground Reservation: "); PrintAllCampgroundInfoInPark(park); int userInputCampgroundId = CLIHelper.GetInteger("\nWhich Campground number (Enter 0 to cancel)?"); if (userInputCampgroundId == 0) { Console.WriteLine("Cancelled! Press any key to continue."); Console.ReadKey(); return; } if (GetCampgroundById(userInputCampgroundId, campgrounds) == null) { Console.WriteLine("Not a valid campground! Press any key to continue."); Console.ReadKey(); return; } //Once valid campground has been chosen --> Get good dates for query DateTime checkIn = CLIHelper.GetDateTime("Check-in date: "); DateTime checkOut = CLIHelper.GetDateTime("Check-out date: "); List <Site> availableSitesFromCampgrounds = new List <Site>(); bool gotDates = false; bool showReservationPrompt = false; while (!gotDates) { availableSitesFromCampgrounds = siteSqlDal.GetAvailableSitesFromCampground(userInputCampgroundId, checkIn, checkOut); if (checkOut.CompareTo(checkIn) <= 0) { Console.WriteLine("Cannot check-out earlier or same day as check-in. Press any key to continue"); Console.ReadKey(); showReservationPrompt = false; gotDates = true; //could allow user a choice to return or enter new dates } else if (availableSitesFromCampgrounds.Count < 1) { string dateReset = CLIHelper.GetString("\nThere are no available sites. \nWould you like to enter an alternate date range?\n\tYes or No?").ToLower(); if (dateReset == "yes" || dateReset == "y") { Console.WriteLine(); checkIn = CLIHelper.GetDateTime("Check-in date: "); checkOut = CLIHelper.GetDateTime("Check-out date: "); gotDates = false; } else if (dateReset == "no" || dateReset == "n") { gotDates = true; } else { Console.WriteLine("Invalid input. Try again"); gotDates = false; } } else { showReservationPrompt = true; gotDates = true; } } if (showReservationPrompt) { int daysReserved = checkOut.Subtract(checkIn).Days; Console.WriteLine("Site Id".PadRight(10) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(20) + "Utility".PadRight(15) + "Cost\n"); foreach (Site site in availableSitesFromCampgrounds) { Console.WriteLine(site.GetPrintString(daysReserved, GetCampgroundById(userInputCampgroundId, campgrounds).DailyFee)); } Console.WriteLine(); MakeReservationPrompts(checkIn, checkOut, availableSitesFromCampgrounds); done = true; } } }