private List <Site> GetAvailableSites(Campground selectedCampground, List <int> bookedSiteIds) { //assemble list of sites in campground from database //if a site's ID is NOT in the list of booked site IDs, it is added to list of *available sites* SiteDAL dal = new SiteDAL(DatabaseConnection); List <Site> allSitesInCampground = dal.AllSitesInCampground(selectedCampground.CampgroundId); List <Site> availableSites = new List <Site>(); foreach (Site thisSite in allSitesInCampground) { bool booked = false; foreach (int bookedId in bookedSiteIds) { if (thisSite.SiteId == bookedId) { booked = true; } } if (booked == false) { availableSites.Add(thisSite); } } return(availableSites); }
public bool DisplayReservationMenu() { //ParkReservationDAL parkReservationDAL = new ParkReservationDAL(connectionString); Console.WriteLine("Which Campground? (Press 0 to Cancel)"); int selection = CLIHelper.GetInteger(); if (selection == 0) { return(false); } else { _userChoiceCampground = _userChoiceCampgroundList[selection - 1]; Console.WriteLine(); Console.WriteLine("What is the Arrival Date? mm/dd/yyyy"); arrivalDate = CLIHelper.GetDate(Console.ReadLine()); Console.WriteLine("What is the Departure Date? mm/dd/yyyy"); departureDate = CLIHelper.GetDate(Console.ReadLine()); //List<CampSite> campSites = parkReservationDAL.GetCampSitesInCampGround(userCampground); List <CampSite> reservations = parkReservationDAL.GetAvailableReservations(_userChoiceCampground, arrivalDate, departureDate); amtOfDays = (departureDate - arrivalDate).Days; DisplayCampsites(reservations); DisplayReservationCommands(reservations); return(true); } }
/// <summary> /// Searches for sites available for reservation given arrival and departure dates /// </summary> /// <param name="campground">The campground to filter sites by</param> private void RunSiteSearch(Campground campground) { bool found = false; while (!found) { DateTime arrivalDate = GetDate(campground.OpenFromMonth, campground.OpenToMonth, "arrival", DateTime.Now); DateTime departureDate = GetDate(campground.OpenFromMonth, campground.OpenToMonth, "depature", arrivalDate); IList <Site> sites = GetAvailableSites(campground, arrivalDate, departureDate); if (sites.Count > 0) { found = true; BookReservation(sites, arrivalDate, departureDate); } else { string answer; do { Console.Write("No results found. Would you like to enter an alternate date range? (Y or N) "); answer = Console.ReadLine().Trim().ToUpper(); } while (answer != "Y" && answer != "N"); if (answer == "N") { return; } } } }
public static Campground SelectFrom(List <Campground> someCamps) { Campground output = new Campground(); Console.Clear(); Campground.DrawInfoHead(); foreach (Campground item in someCamps) { int position = someCamps.IndexOf(item) + 1; Console.Write($"[{position}]"); item.DrawInfo(); } while (output.selected == false) { string input = Console.ReadKey(true).KeyChar.ToString(); int.TryParse(input, out int x); if (0 < x && x <= someCamps.Count) { output = someCamps[x - 1]; output.selected = true; } } return(output); }
private void CampgroundReservationMenu(Campground campground) { Console.WriteLine("Would you like an advanced search? Y/N"); bool loopingAdvancedSearch = true; while (loopingAdvancedSearch) { string input = Console.ReadLine().ToUpper(); if (input == "Y") { CampgroundReservationAdvanceMenu(campground); loopingAdvancedSearch = false; } else if (input == "N") { CampgroundReservationBasicMenu(campground); loopingAdvancedSearch = false; } else { DisplayInvalidOption(); } } }
/// <summary> /// Makes a list of all campgrounds in database, using the campground object. /// </summary> /// <param name="inputCommand"></param> /// <returns></returns> public List <Campground> GetAvailableCampgroundsFromParks(string inputCommand) { List <Campground> campgrounds = new List <Campground>(); using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); string SQLGetAllCampgrounds = $"SELECT * FROM campground WHERE park_id = {inputCommand};"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = SQLGetAllCampgrounds; cmd.Connection = connection; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Campground newCampground = new Campground(); newCampground.ID = Convert.ToString(reader["campground_id"]); newCampground.Name = Convert.ToString(reader["name"]); newCampground.OpenFrom = Convert.ToInt32(reader["open_from_mm"]); newCampground.OpenTo = Convert.ToInt32(reader["open_to_mm"]); newCampground.DailyFee = Convert.ToDouble(reader["daily_fee"]); // Add the continent to the output list campgrounds.Add(newCampground); } } return(campgrounds); }
public void ViewAllSelectedSites(Campground campground, string start, string end) { bool exit = false; while (!exit) { Console.Clear(); Dictionary <int, Site> Sites = _park.GetSelectedSiteDictionary(campground, start, end); if (Sites.Count > 0) { Console.WriteLine($"| {"Site ID".PadRight(15)} | " + $"| {"Site Number".PadRight(15)} | " + $"| {"Max Occup.".PadRight(15)}" + $"| {"Accessible?".PadRight(15)} | " + $"| {"Max RVLength".PadRight(15)} | " + $"| {"Utility".PadRight(15)} |" + $"| {"Cost".PadRight(15)} "); Console.WriteLine(new string('-', 120)); foreach (KeyValuePair <int, Site> item in Sites) { Console.WriteLine($"| {item.Key.ToString().PadRight(15)} | " + $"| {item.Value.SiteNumber.ToString().PadRight(15)} | " + $"| {item.Value.MaxOccupancy.ToString().PadRight(15)}" + $"| {item.Value.Accessible.ToString().PadRight(15)} | " + $"| {item.Value.MaxRVLength.ToString().PadRight(15)} | " + $"| {item.Value.Utilities.ToString().PadRight(15)} |" + $"| {item.Value.TotalFee.ToString("C")}".PadRight(15)); } var selection = NationalPark.GetInteger("Which site would you like to reserve? Enter the site ID to select, or enter 0 to return"); if (selection == 0) { Console.Clear(); exit = true; } else if (Sites.ContainsKey(selection)) { Console.WriteLine("What name should the reservation be made under?"); string reservationName = Console.ReadLine(); int reservationID = _park.AddReservation(Sites[selection], reservationName, start, end); Console.WriteLine($"you're reservation number is {reservationID}. Thanks!"); Console.ReadKey(); exit = true; } else { Console.WriteLine("Please only enter a site number that exists"); Console.ReadKey(); } } else { Console.WriteLine("There are no available campsites for this date range. Please select another campground or date range."); Console.ReadKey(); exit = true; } } }
/// <summary> /// Determines if the campground is closed during part or all of a date range. This is redundant /// to SQL query filters, but allows for a custom message in this case. /// </summary> /// <param name="campground"></param> /// <param name="arrivalDate"></param> /// <param name="departureDate"></param> /// <returns></returns> private bool IsClosed(Campground campground, DateTime arrivalDate, DateTime departureDate) { return ((arrivalDate.Month < campground.Open_From_MM) || (departureDate.Month > campground.Open_To_MM) || ((arrivalDate.Year != departureDate.Year) && (campground.Open_From_MM != 1) && (campground.Open_To_MM != 12))); }
public void SearchMenu() { Console.WriteLine(); PrintAllCampgrounds(); Console.WriteLine(); Console.Write("Which campground (enter 0 to cancel)? "); int campgroundNum; bool isNumeric = int.TryParse(Console.ReadLine(), out campgroundNum); while (!isNumeric || campgroundNum < 0) { Console.Write("Please enter a valid selection: "); isNumeric = int.TryParse(Console.ReadLine(), out campgroundNum); Console.WriteLine(); } if (campgroundNum == 0) { ParkMenu(); } else { Console.Write("What is the arrival date? "); DateTime arrivalDate = Convert.ToDateTime(Console.ReadLine()); Console.Write("What is the departure date? "); DateTime departureDate = Convert.ToDateTime(Console.ReadLine()); SiteSqlDAL siteDAL = new SiteSqlDAL(connectionString); CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Site> siteList = siteDAL.GetAvailableSites(campgroundNum, arrivalDate, departureDate); Console.WriteLine(); Console.WriteLine("Campground".PadRight(20) + "Site No.".PadRight(15) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "RV Len".PadRight(15) + "Utility".PadRight(15) + "Cost".PadRight(15)); Campground campground = campgroundDAL.GetCampground(campgroundNum); foreach (Site site in siteList) { //string siteNa = site.Campground_id.ToString(); string siteNo = site.Site_number.ToString(); string siteMO = site.Max_occupancy.ToString(); string siteA = site.Accessible.ToString(); string siteMRV = site.Max_rv_length.ToString(); string siteU = site.Utilities.ToString(); string campNa = campground.Name.ToString(); int lenghtOfStay = (int)(departureDate - arrivalDate).TotalDays; decimal costOfStay = lenghtOfStay * campground.Daily_fee; string costOfStayString = costOfStay.ToString("C"); Console.WriteLine(campNa.PadRight(20) + siteNo.PadRight(20) + siteMO.PadRight(15) + siteA.PadRight(10) + siteMRV.PadRight(15) + siteU.PadRight(15) + costOfStayString.PadRight(5)); } ReservationMenu(arrivalDate, departureDate); } }
/// <summary> /// Checks date range from user against open and close date range of campground and its associated sites /// </summary> /// <param name="currentCampground"></param> /// <param name="desiredReservationDates"></param> /// <returns>The open status of the campground for the requested date range</returns> private bool CheckDateRange(Campground currentCampground, DateTime[] desiredReservationDates) { bool validDateRange = false; if (desiredReservationDates[0].Month >= currentCampground.OpenMonth && desiredReservationDates[0].Month <= currentCampground.CloseMonth && desiredReservationDates[1].Month >= currentCampground.OpenMonth && desiredReservationDates[1].Month <= currentCampground.CloseMonth) { validDateRange = true; } return(validDateRange); }
/// <summary> /// Searches for available sites at a given campground and given timespan. /// </summary> /// <param name="campground">The campground for the search taking place.</param> private List <Site> SearchForAvailableSites(Campground campground, DateTime arrivalDate, DateTime departureDate) { List <Site> availableSites = new List <Site>(); SiteSqlDAL ssDal = new SiteSqlDAL(ConnectionString); availableSites.AddRange(ssDal.GetAvailableSites(campground, arrivalDate, departureDate)); return(availableSites); }
/// <summary> /// Returns all of the available sites from a selected campground, given a reservation date range. /// </summary> /// <param name="campground">A particular campground object specified by the user.</param> /// <param name="start">The start of a reservation date in yyyy-mm-dd format.</param> /// <param name="end">the end of a reservation date in yyyy-mm-dd format.</param> /// <returns>A dictionary of all available sites from a particular campground in a set date range, with the key being the site ID and the value being the site class object</returns> public Dictionary <int, Site> GetSelectedSiteDictionary(Campground campground, string start, string end) { List <Site> list = _db.GetSelectedSites(campground.CampgroundID, start, end); Dictionary <int, Site> SiteDictionary = new Dictionary <int, Site>(); foreach (Site item in list) { SiteDictionary.Add(item.SiteID, item); } return(SiteDictionary); }
/// <summary> /// Returns a dictionary of all sites from a particular campground, with the key being the site ID and the value being the site class object. /// </summary> /// <param name="campground">A campground from which the sites will be returned</param> /// <returns>A dictionary of all sites from a particular campground, with the key being the site ID and the value being the site class object</returns> public Dictionary <int, Site> GetSiteDictionary(Campground campground) { List <Site> list = _db.GetAllSites(campground.CampgroundID); Dictionary <int, Site> SiteDictionary = new Dictionary <int, Site>(); foreach (Site item in list) { SiteDictionary.Add(item.SiteID, item); } return(SiteDictionary); }
/// <summary> /// Creates a new instance of a Campground using data from SqlDataReader /// </summary> /// <param name="reader"></param> /// <returns></returns> private Campground PopulateCampgroundFromReader(SqlDataReader reader) { Campground item = new Campground(); item.Id = (int)reader["campground_id"]; item.ParkId = (int)reader["park_id"]; item.Name = (string)reader["name"]; item.OpenFrom = (int)reader["open_from_mm"]; item.ClosedFrom = (int)reader["open_to_mm"]; item.DailyFee = (decimal)reader["daily_fee"]; return(item); }
/// <summary> /// Populates a Campground class object from when called upon by a SQLDataReader /// </summary> /// <param name="reader">The SqlDataReader object that is created from a database</param> /// <returns></returns> private Campground PopulateCampgroundInfoFromReader(SqlDataReader reader) { Campground item = new Campground(); item.CampgroundID = (int)reader["campground_id"]; item.CampgroundName = (string)reader["name"]; item.OpenFrom = (int)reader["open_from_mm"]; item.OpenTill = (int)reader["open_to_mm"]; item.DailyFee = (decimal)reader["daily_fee"]; return(item); }
/// <summary> /// Collects requested date range for reservation /// </summary> /// <param name="campgroundId"></param> /// <param name="campgrounds"></param> /// <returns>Array of datetime representing requested arrival date and requested departure date</returns> private DateTime[] SearchForCampgroundReservation(int campgroundId, IList <Campground> campgrounds) { DateTime[] desiredReservationDates = new DateTime[2]; Campground currentCampground = new Campground(); foreach (var campground in campgrounds) { if (campgroundId == campground.CampgroundId) { currentCampground = campground; break; } } while (true) { Console.WriteLine(); Console.WriteLine("What is the arrival date (YYYY-MM-DD) ?:"); Console.Write("Year (YYYY): "); int arrivalYear = CLIHelper.GetInteger(Console.ReadLine()); Console.Write("Month (MM): "); int arrivalMonth = CLIHelper.GetInteger(Console.ReadLine()); Console.Write("Day (DD): "); int arrivalDay = CLIHelper.GetInteger(Console.ReadLine()); DateTime arrivalDate = new DateTime(arrivalYear, arrivalMonth, arrivalDay); desiredReservationDates[0] = arrivalDate; Console.WriteLine(); Console.WriteLine("What is the departure date?:"); Console.Write("Year (YYYY): "); int departureYear = CLIHelper.GetInteger(Console.ReadLine()); Console.Write("Month (MM): "); int departureMonth = CLIHelper.GetInteger(Console.ReadLine()); Console.Write("Day (DD): "); int departureDay = CLIHelper.GetInteger(Console.ReadLine()); DateTime departureDate = new DateTime(departureYear, departureMonth, departureDay); desiredReservationDates[1] = departureDate; bool validDateRange = CheckDateRange(currentCampground, desiredReservationDates); if (validDateRange) { break; } Console.WriteLine("Invalid Date Entered, Please Try Again"); } return(desiredReservationDates); }
public bool CheckParkOpenMonths(Campground campground, DateTime arrivalDate, DateTime departDate) { bool isOpen = true; int arriveMonth = arrivalDate.Month; int departMonth = departDate.Month; if (arriveMonth < campground.open_from_mm || departMonth > campground.open_to_mm) { isOpen = false; } return(isOpen); }
private void SearchForAvailableCampsites(Campground selectedCampground, DateTime?startDate, DateTime?endDate, int numberOfDaysToReserve) { // Used to get back into reservation info-getting loop if error throws us back here bool trigger = false; double totalCost = selectedCampground.DailyFee * numberOfDaysToReserve; Campsite_DAL site_DAL = new Campsite_DAL(); campsites = site_DAL.GetCampsitesByCampground(selectedCampground.CampID, startDate, endDate); Console.WriteLine(); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine("Site No.".PadRight(15) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(20) + "Utility".PadRight(15) + "Cost of Reservation"); if (campsites.Count == 0) { ClearCurrentConsoleLine(); ClearCurrentConsoleLine(); Console.WriteLine(); Console.Clear(); Console.WriteLine("Sorry! Looks like there are no available campsites for your date range. Please try a different campground or a new date range."); Thread.Sleep(2000); GetCampgroundsByPark(); return; } foreach (var site in campsites) { Console.WriteLine($"{site.SiteNumber}".PadRight(15) + $"{site.MaxOccupancy}".PadRight(15) + $"{BoolChecker(site.Accessible)}".PadRight(15) + $"{RVChecker(site.MaxRVLength)}".PadRight(20) + $"{BoolChecker(site.UtilityAccess)}".PadRight(15) + $"{totalCost:c}"); } while (trigger == false) { try { trigger = true; BookReservation(startDate, endDate); return; } catch (Exception) { ClearCurrentConsoleLine(); ClearCurrentConsoleLine(); Console.WriteLine("There was a problem with your information. Please try again."); Thread.Sleep(1000); ClearCurrentConsoleLine(); ClearCurrentConsoleLine(); trigger = false; } } }
public List <Site> CheckAvailabilty(DateTime start, DateTime end) { DateRange requestedRange = new DateRange(start, end); List <Site> availableSites = new List <Site>(); Campground selectedCampground = new Campground(); foreach (var campground in Park.Campgrounds) { if (campground.CampgroundID == this.CampgroundID) { selectedCampground = campground; } } try { using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("SELECT site_id FROM site WHERE site.site_id NOT IN " + "(SELECT reservation.site_id FROM reservation WHERE @StartDate BETWEEN reservation.from_date " + "AND reservation.to_date OR @EndDate BETWEEN reservation.from_date " + "AND reservation.to_date) AND @campgroundId = site.campground_id;", conn); cmd.Parameters.AddWithValue("@StartDate", this.Start); cmd.Parameters.AddWithValue("@EndDate", this.End); cmd.Parameters.AddWithValue("@campgroundId", selectedCampground.CampgroundID); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int siteId = Convert.ToInt32(reader["site_id"]); foreach (var campsite in selectedCampground.Sites) { if (siteId == campsite.SiteID) { availableSites.Add(campsite); } } } } } catch (SqlException ex) { Console.WriteLine(ex.Message); } return(availableSites); }
private Campground RowToObject(SqlDataReader reader) { Campground campground = new Campground(); campground.CampgroundId = Convert.ToInt32(reader["campground_id"]); campground.ParkId = Convert.ToInt32(reader["park_id"]); campground.CampName = Convert.ToString(reader["name"]); campground.Open_From_MM = Convert.ToInt32(reader["open_from_mm"]); campground.Open_To_MM = Convert.ToInt32(reader["open_to_mm"]); campground.Daily_Fee = Convert.ToDecimal(reader["daily_fee"]); return(campground); }
public void PrintCampGrounds(int parkId) { CampGroundSqlDAL dal = new CampGroundSqlDAL(DatabaseConnection); List <Campground> campgrounds = dal.GetCampGroundsInPark(parkId); _campgroundDictionary.Clear(); for (int i = 1; i <= campgrounds.Count; i++) { Campground campground = campgrounds[i - 1]; Console.WriteLine($"({campgrounds[i - 1].Id}){campgrounds[i - 1].Name,-20} {campgrounds[i - 1].OpenFromMonthstr,-15} {campgrounds[i - 1].OpenToMonthstr,-20} {campgrounds[i - 1].DailyFee.ToString("c"),-20}"); _campgroundDictionary.Add(i, campground); } }
public Campground GetCampgroundById(int campgroundId, List <Campground> campgrounds) { Campground result = null; foreach (Campground campground in campgrounds) { if (campground.Id == campgroundId) { result = campground; } } return(result); }
private void DisplayCampgrounds(Park park) { _campgrounds.Clear(); List <Campground> campgroundsList = _campgroundDAL.GetAllCampgrounds(park); Console.WriteLine(); for (int index = 0; index < campgroundsList.Count; index++) { Campground campground = campgroundsList[index]; Console.WriteLine("{0, -4}{1, -20}{2, -20}{3, -20}{4, -20}", "#" + (index + 1), campground.Name, campground.OpenFromMonthStr, campground.OpenToMonthStr, campground.DailyFee.ToString("c")); _campgrounds.Add(index + 1, campground); } }
/// <summary> /// Goes through list of campgrounds, printing relevant info to console /// </summary> /// <param name="campgrounds"></param> private void PresentCampgroundInfo(IList <Campground> campgrounds) { Console.WriteLine("Name".PadLeft(10).PadRight(40) + "Open".PadRight(10) + "Close".PadRight(15) + "Daily Fee"); for (int i = 0; i < campgrounds.Count; i++) { Campground c = campgrounds[i]; int listNumber = i + 1; string campground = campgrounds[i].Name; string firstMonth = GetMonthFromSQLInt(c.FirstMonthOpen); string lastMonth = GetMonthFromSQLInt(c.LastMonthOpen); double dailyFee = campgrounds[i].DailyFee; Console.WriteLine($"#{listNumber})".PadRight(6) + $"{campground}".PadRight(34) + $"{firstMonth}".PadRight(10) + $"{lastMonth}".PadRight(15) + $"{dailyFee:C2}"); } }
public void DateRangeSubMenu(int parkID) { Console.Clear(); Console.WriteLine("{0, -20}{1, -20}{2, -20}{3, -20}", " Name", " Open", " Close", " Daily Fee"); PrintCampGrounds(parkID); Console.WriteLine(); Console.Write($"Which Campground (enter 0 to return to main menu)?"); string campgroundSelection = Console.ReadLine(); int selection = int.Parse(campgroundSelection); int resID = 0; if (_campgroundDictionary.ContainsKey(selection)) { Campground campground = _campgroundDictionary[selection]; Console.Write("What is your arrival date? (yyyy/mm/dd)"); DateTime arrivalDate = DateTime.Parse(Console.ReadLine()); Console.Write("What is your departure date? (yyyy/mm/dd)"); DateTime departureDate = DateTime.Parse(Console.ReadLine()); SiteSqlDAL dal = new SiteSqlDAL(DatabaseConnection); var listOfSites = dal.GetSitesInCampground(campground.Id); ReservationSqlDAL resDal = new ReservationSqlDAL(DatabaseConnection); List <Site> availableSites = resDal.ReturnSites(selection, arrivalDate, departureDate); Console.WriteLine(); Console.WriteLine("Results matching your search criteria"); Console.WriteLine("{0, -15}{1, -15}{2, -15}{3, -15}{4, -20}", "Site Number", "Max Occupancy", "Accesibility", "Max RV Length", "Utilities"); foreach (var item in availableSites) { Console.WriteLine($"{item.SiteNumber, -15} {item.MaxOccupancy, -15} {item.Accessible, -15} {item.MaxRVLength, -15} {item.Utilities, -15}"); } Console.WriteLine("What site should be reserved?"); char tempSiteRes = Console.ReadKey().KeyChar; Console.WriteLine(); Console.WriteLine("What name should the reservation be made under?"); string resName = Console.ReadLine(); Console.ReadKey(); bool wasSuccesful = resDal.InsertReservation(tempSiteRes, resName, arrivalDate, departureDate); if (wasSuccesful) { resID = resDal.GetReservationID(tempSiteRes, resName, arrivalDate, departureDate); Console.WriteLine("Your reservation number is: " + resID); Console.ReadKey(); } } }
/// <summary> /// Prints list of campgrounds with headers /// </summary> /// <param name="parkId"></param> private void PrintCampgrounds(int parkId) { List <Campground> campgrounds = new List <Campground>(); Console.WriteLine("Park Campgrounds"); Console.WriteLine(parkDAO.GetParkName(parkId)); Console.WriteLine(); Console.WriteLine(Campground.PrintCampgroundHeader()); // generate list of campgrounds to display for campground selection screen campgrounds = campgroundDAO.GetCampgrounds(parkId); foreach (Campground campground in campgrounds) { Console.WriteLine(campground.ToString()); validCampgrounds.Add(campground.Campground_Id); } Console.WriteLine(); }
private void SitesResultsMenu(Park selectedPark, Campground campgroundChoice, string[] reservationDates, decimal dailyFee) { IList <Site> sites = siteDAO.GetAvailableReservationsSingleCapmground(campgroundChoice.CampgroundId, reservationDates[0], reservationDates[1]); int siteChoice = -1; Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine(String.Format("{0,-40} {1, -20} {2,-20} {3,-20} {4,-20} {5,-20}", "Site No.", "Max Occup.", "Accessible?", "Max RV Length", "Utility", "Cost")); Console.WriteLine(); for (int i = 0; i < sites.Count; i++) { Console.WriteLine(String.Format("{0,-40} {1, -20} {2,-20} {3,-20} {4,-20} {5,-20}", sites[i].SiteNumber, sites[i].MaxOccupancy, sites[i].Accessible, sites[i].MaxRVLength, sites[i].Utilities, dailyFee)); } Console.WriteLine(); while (siteChoice < 1 || siteChoice > sites.Count) { Console.Write("Which site should be reserved (enter 0 to cancel)?"); if (int.TryParse(Console.ReadLine(), out siteChoice)) { if (siteChoice == 0) { return; } foreach (Site site in sites) { if (site.SiteNumber == siteChoice) { Console.Write("What name should the reservation be made under?"); string customerName = Console.ReadLine(); reservationDAO.MakeAReservation(site, customerName, reservationDates[0], reservationDates[1]); return; } } } else { Console.WriteLine("Invalid Input. Please enter a valid number."); } } }
private void CheckAvailability() { GetAllCampgrounds(); int campgroundId = CLIHelper.GetInteger("Please select which Campground Id you would like to check the availability of : "); DateTime startDate = CLIHelper.GetDateTime("When would you like start your reservation?"); DateTime endDate = CLIHelper.GetDateTime("When would you like end your reservation?"); CampgroundDAL cdal = new CampgroundDAL(DatabaseConnection); Campground reservedCampground = cdal.GetCampground(campgroundId); if (startDate.Month < reservedCampground.OpenFromMM) { Console.WriteLine("The campground is not open yet."); return; } if (endDate.Month > reservedCampground.OpenToMM) { Console.WriteLine("The campground is closed for the year."); return; } Console.WriteLine(); SiteDAL sdal = new SiteDAL(DatabaseConnection); List <Site> site = sdal.GetAvailableCampsites(campgroundId, startDate, endDate); PrintSites(site); Console.ReadLine(); string input = CLIHelper.GetString(" Would you Like to confirm your reservation?").ToLower(); if (input == "yes" || input == "y") { HelpMakeReservation(campgroundId, startDate, endDate); } else { Console.WriteLine("Returning to Main Menu"); Console.ReadLine(); } }
/// <summary> /// Gets list of sites available for reservation given arrival and departure dates /// </summary> /// <param name="campground">Campground to filter sites by</param> /// <param name="arrivalDate">Arrival date for the reservation</param> /// <param name="departureDate">Departure date for the reservation</param> /// <returns></returns> private IList <Site> GetAvailableSites(Campground campground, DateTime arrivalDate, DateTime departureDate) { Console.WriteLine("".PadRight(lineWidth, lineChar)); Console.WriteLine("Results Matching Your Search Criteria\n"); Console.WriteLine("Site No.".PadRight(12) + "Max Occup.".PadRight(14) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(17) + "Utility".PadRight(12) + "Cost".PadRight(10)); Console.WriteLine("".PadRight(lineWidth, dottedChar)); IList <Site> sites = siteDAO.GetAvailableSites(campground.CampgroundId, arrivalDate, departureDate); for (int i = 0; i < sites.Count; i++) { decimal cost = (decimal)(departureDate - arrivalDate).TotalDays * campground.DailyFee; Console.WriteLine(sites[i].ToString() + $"{cost:C2}".ToString().PadRight(10)); } Console.WriteLine(); return(sites); }
private void HelpMakeReservation(int campgroundId, DateTime startDate, DateTime endDate) { CampgroundDAL cdal = new CampgroundDAL(DatabaseConnection); Campground reservedCampground = cdal.GetCampground(campgroundId); SiteDAL sdal = new SiteDAL(DatabaseConnection); string name = CLIHelper.GetString("Enter Name"); int siteID = CLIHelper.GetInteger("Please select a Site"); int reservationId = sdal.ReserveCampsite(campgroundId, siteID, startDate, endDate, name); int lengthOfStay = (endDate - startDate).Days; string cost = (reservedCampground.DailyFee * lengthOfStay).ToString("C"); //sdal.GetPrice(lengthOfStay, campgroundId); Console.WriteLine("You have successfully booked your Reservation"); Console.WriteLine($"Your reservation number is {reservationId}."); Console.WriteLine($"Your bill is {cost}"); Console.ReadLine(); }