// GET: Campground public ActionResult Index(int id) { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Campground> campgroundList = campgroundDAL.ListCampgrounds(id); return(View("Index", campgroundList)); }
public void GetCampgroundsFromPark_ReturnsCampgrounds() { // Arrange CampgroundSqlDAL dal = new CampgroundSqlDAL(ConnectionString); int ID = 0; using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); SqlCommand command = new SqlCommand("SELECT park_id FROM park", conn); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ID = Convert.ToInt32(reader["park_id"]); } } // Act Campground test = new Campground(); IList <Campground> campgrounds = dal.GetCampgroundsFromPark(ID); // Assert Assert.AreEqual(1, campgrounds.Count); }
public void TestCampgroundList() { TransactionScope test = new TransactionScope(); ParkSqlDAL parkDAL = new ParkSqlDAL(connectionString); List <Park> park = parkDAL.GetParks(); CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Campground> testNumberOfCampsAcadia = campgroundDAL.GetAllCampgroundFromPark(park[0]); List <Campground> testNumberOfCampsArches = campgroundDAL.GetAllCampgroundFromPark(park[1]); List <Campground> testNumberOfCampsCuyahogaValley = campgroundDAL.GetAllCampgroundFromPark(park[2]); //assert bool outputAcadia_doesCampCountNumberMatch = testNumberOfCampsAcadia.Count == 3; Assert.IsTrue(outputAcadia_doesCampCountNumberMatch); bool outputArches_doesCampCountNumberMatch = testNumberOfCampsArches.Count == 3; Assert.IsTrue(outputArches_doesCampCountNumberMatch); bool outputCuyahogaValley_doesCampCountNumberMatch = testNumberOfCampsCuyahogaValley.Count == 1; Assert.IsTrue(outputCuyahogaValley_doesCampCountNumberMatch); test.Dispose(); }
public Reservation SearchDateAvailabilityByCampground() { string campground = CLIHelper.GetString("Please enter campground name: "); DateTime startDate = CLIHelper.GetDateTime("Please enter a start date: "); DateTime endDate = CLIHelper.GetDateTime("Please enter an end date: "); Reservation reservation = new Reservation() { CampgroundName = campground, FromDate = startDate, ToDate = endDate }; CampgroundSqlDAL dal = new CampgroundSqlDAL(); List <Site> siteList = dal.SearchDateAvailabilityByCampground(reservation); if (siteList.Count < 1) { Console.WriteLine("No available sites for this date range."); return(null); } else { siteList.ForEach(site => Console.WriteLine(site)); } return(reservation); }
private void ViewCampgrounds(Park selectedPark) { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Campground> campgrounds = campgroundDAL.GetCampgrounds(selectedPark); Console.WriteLine($"#:".PadRight(8) + "Campground Name".PadRight(41) + "Open From:".PadRight(16) + "Open To:".PadRight(16) + "Daily Fee".PadRight(5)); foreach (Campground campground in campgrounds) { Console.WriteLine(campground.ToString()); } Console.WriteLine("Select A Command"); Console.WriteLine("1) Search for Available Reservation"); Console.WriteLine("2) Return To Previous Screen"); string campgroundMenuInput = Console.ReadLine(); switch (campgroundMenuInput) { case "1": input = "4"; break; case "2": input = "2"; break; default: Console.WriteLine("Please select a valid input. Press enter to try again."); Console.ReadLine(); break; } }
private IList <Campground> GetCampgrounds(int parkId) { ICampgroundDAL campdal = new CampgroundSqlDAL(DatabaseConnectionString.DatabaseString); IList <Campground> campgrounds = campdal.GetCampgrounds(parkId); return(campgrounds); }
public static int GetCampgroundInteger(string message, string connectionString, int selectedParkId) { string userInput = String.Empty; int intValue = 0; int numberOfAttempts = 0; CampgroundSqlDAL campgroundDal = new CampgroundSqlDAL(connectionString); List <Campground> campgroundsForSelectedPark = campgroundDal.GetListOfCampgrounds(selectedParkId); do { if (numberOfAttempts > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" Invalid input format. Please try again\n"); Console.ForegroundColor = ConsoleColor.White; } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write(message); Console.ForegroundColor = ConsoleColor.White; userInput = Console.ReadLine(); numberOfAttempts++; Console.WriteLine(); }while (!int.TryParse(userInput, out intValue) || intValue > campgroundsForSelectedPark.Count); return(intValue); }
private void GetAllReservationsFor30DaysByPark(string parkName) { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(); List <Reservation> reservations = campgroundDAL.GetAllReservationsForNext30Days(parkName); bool returnToPrevious = false; do { Console.Clear(); Console.WriteLine("{0,-18}{1,-10}{2, -30}{3,-13}{4,-13}", "Confirmation ID", "Site", "Name", "From-Date", "To-Date"); Console.WriteLine(String.Format("").PadRight(80, '=')); foreach (var reserv in reservations) { Console.WriteLine(reserv.ReservationID.ToString().PadRight(18) + reserv.SiteID.ToString().PadRight(10) + reserv.Name.PadRight(30) + reserv.FromDate.ToShortDateString().PadRight(13) + reserv.ToDate.ToShortDateString().PadRight(13)); } Console.WriteLine(); Console.WriteLine("Press (Enter) to return to previous screen"); char userInput = Console.ReadKey().KeyChar; returnToPrevious = userInput == (char)Keys.Return ? true : false; } while (!returnToPrevious); }
// LEVEL: CAMPGROUNDS ///////////////////////////////////////// private int[] GetAllCampgrounds_View(int parkID) { CampgroundSqlDAL dal = new CampgroundSqlDAL(DatabaseConnection); Console.WriteLine( " ".PadRight(10) + "Name".PadRight(40) + "Open".PadRight(15) + "Close".PadRight(15) + "Daily Fee".PadLeft(15)); IList <Campground> campgrounds = dal.GetCampgroundsFromPark(parkID); if (campgrounds.Count > 0) { int[] output = new int[campgrounds.Count]; int i = 0; foreach (Campground campground in campgrounds) { this.PrintCampground(campground.Campground_Id, campground.Name, campground.Opening_Month, campground.Closing_Month, campground.Daily_Fee); output[i] = campground.Campground_Id; i++; } return(output); } else { Console.WriteLine("**** NO RESULTS ****"); return(new int[0]); } }
private IList <Campground> GetAllCampgrounds(int park_Id) { ICampground dal = new CampgroundSqlDAL(DatabaseConnectionString); IList <Campground> campground = dal.GetAllCampgrounds(park_Id); return(campground); }
public void GetCampgroundsAtPark_InsertedCampgroundExists() { using (TransactionScope transaction = new TransactionScope()) { CampgroundSqlDAL testClass = new CampgroundSqlDAL(connectionString); Park tempPark = new Park(); tempPark.Area = 0; tempPark.Description = "TEST DESCRIPTION"; tempPark.Establish_Date = new DateTime(2000, 1, 1).Date; tempPark.Location = "TEST LOCATION"; tempPark.Name = "TEST PARK"; tempPark.Visitors = 0; int tempPark_parkId = ParkSqlDALTests.InsertFakePark(tempPark); Campground testCamp = new Campground(); testCamp.Daily_Fee = 5.00M; testCamp.Name = "Slimy Valley"; testCamp.Open_From_MM = 5; testCamp.Open_To_MM = 6; testCamp.Park_Id = tempPark_parkId; testCamp.Campground_Id = InsertFakeCampground(testCamp); Campground insertedCampground = testClass.GetCampgroundsAtPark(tempPark_parkId).First(); Assert.IsNotNull(insertedCampground); } }
private void ShowAllCampgroundInAPark(int userInputParkId) { Console.WriteLine("Showing Campgrounds"); CampgroundSqlDAL cal = new CampgroundSqlDAL(connectionString); List <Campground> allCampgrounds = cal.GetAllCampgrounds(userInputParkId); foreach (Campground c in allCampgrounds) { Console.WriteLine(); Console.WriteLine("Campground_Id " + c.Campground_id); Console.WriteLine("Park ID: " + c.Park_id); Console.WriteLine("Campground Name: " + c.Name); Console.WriteLine("Campground is open from " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(c.Open_from_mm)); Console.WriteLine("Campground closes at " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(c.Open_to_mm)); Console.WriteLine("Campground daily cost: " + c.Daily_fee.ToString("C")); } Console.ReadLine(); Console.WriteLine("Would you like to book one of these sites? (Y/N)"); string input = Console.ReadLine().ToUpper(); if (input == "Y") { int campgroundId = CLIHelper.GetInteger("Please select a Campground ID"); Reservation(campgroundId); } return; }
/// <summary> /// Displays the menu after a park has been selected. /// </summary> public void DisplaySubMenuCLI() { //The menu is "running till they are done with that menu" while (running) { Console.WriteLine(); PrintCommands(); string command = Console.ReadLine(); CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(DatabaseConnection); switch (command) { case Command_ViewCampgrounds: Console.Clear(); DisplayAllCampGrounds(Park); break; case Command_SearchForReservation: BookingSubMenuCLI submenu = new BookingSubMenuCLI(this.Park); submenu.DisplayBookingSubMenu(); break; case Command_Return: running = false; break; default: Console.WriteLine(); Console.WriteLine("Sorry, that's not a valid choice!"); System.Threading.Thread.Sleep(1500); break; } } }
/// <summary> /// Allows the user to view all of the information for any given park /// If the user presses "Q" or "q", they will be brought to the previous menu /// </summary> public void RunCLI() { this.PrintMenu(); string input = Console.ReadLine().ToUpper(); if (input == "Q") { return; } int parkSelection = int.Parse(input); Park selectedPark = this.parks[parkSelection - 1]; Console.Clear(); Console.WriteLine($"Park Information Screen"); Console.WriteLine($"{selectedPark.Name}"); Console.WriteLine($"Location: {selectedPark.Location}"); Console.WriteLine($"Established: {selectedPark.Establish_Date.ToShortDateString()}"); Console.WriteLine($"Area: {selectedPark.Area} sq km"); Console.WriteLine($"Annual Visitors: {selectedPark.Visitors}"); Console.WriteLine(); Console.WriteLine($"{selectedPark.Description}"); Console.WriteLine(); ICampground dal = new CampgroundSqlDAL(DatabaseConnectionString); IList <Campground> campgrounds = dal.GetAllCampgrounds(selectedPark.Park_Id); ParkCampgroundsMenu campgroundsMenu = new ParkCampgroundsMenu(campgrounds); campgroundsMenu.RunCLI(); return; }
public void GetAllCampgroundsTest() { int parkId; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO park VALUES ('fake park', 'fake location', '9/9/9999', 99, 99, 'fake description');", conn); cmd.ExecuteNonQuery(); cmd = new SqlCommand("SELECT CAST(SCOPE_IDENTITY() as int);", conn); parkId = Convert.ToInt32(cmd.ExecuteScalar()); } int campgroundId; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand($"INSERT INTO campground VALUES ({parkId}, 'fake campground', '1', '2', '99');", conn); cmd.ExecuteNonQuery(); cmd = new SqlCommand("SELECT CAST(SCOPE_IDENTITY() as int);", conn); campgroundId = Convert.ToInt32(cmd.ExecuteScalar()); } CampgroundSqlDAL dal = new CampgroundSqlDAL(connectionString); List <Campground> campground = dal.GetAllCampgrounds(parkId); CollectionAssert.Contains(campground, campgroundId); }
private void GetCampgroundAvailability(Dictionary <int, Campground> campgrounds) { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(); int campground = CLIHelper.GetInteger("Which Campground (enter 0 to cancel):"); bool returnToPrevious = campground == int.Parse(command_Cancel); //Return to previous screen if user enters 0 if (returnToPrevious) { return; } while (!campgrounds.ContainsKey(campground)) { campground = campground = CLIHelper.GetInteger("Invalid choice. Please pick a campground Site number from available list:"); } ; bool stillBooking = false; do { DateTime startDate = CLIHelper.GetDateTime("Enter start date (YYYY/MM/DD):"); DateTime endDate = CLIHelper.GetDateTime("Enter end date (YYYY/MM/DD):"); var availableSites = campgroundDAL.GetCampgroundAvailability(campgrounds[campground].Name, startDate, endDate); if (availableSites.Count > 0) { List <int> availableSiteNumbers = new List <int>(); int totalReservDays = (int)(endDate - startDate).TotalDays; Console.Clear(); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine(String.Format("").PadRight(30, '=')); Console.WriteLine("{0,3}{1,12}{2,13}{3,14}{4,9}{5,10}{6,7}", "Campground", "Site No.", "Max Occup.", "Accessible?", "RV Len", "Utility", "Cost"); foreach (var site in availableSites) { double cost = campgrounds[campground].Daily_Fee * totalReservDays; availableSiteNumbers.Add(site.SiteNumber); Console.WriteLine(campgrounds[campground].Name.PadRight(17) + site.SiteNumber.ToString().PadRight(12) + site.MaxOccupancy.ToString().PadRight(13) + site.WheelchairAccess.PadRight(11) + site.MaxRVLength.PadRight(10) + site.UtilityHookups.PadRight(9) + cost); } bool reservationSuccessful = BookReservation(availableSiteNumbers, startDate, endDate); if (reservationSuccessful) { stillBooking = false; } } else { Console.WriteLine("Sorry, there are no sites available in the specified date range."); stillBooking = CLIHelper.GetBoolFromYesOrNo("Would you like to enter another date range?"); } } while (stillBooking); }
public void GetAllCampgroundsTest() { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Campground> campgroundsList = campgroundDAL.GetAllCampgrounds(); Assert.IsNotNull(campgroundsList); Assert.AreEqual(campgrounds, campgroundsList.Count); }
public void GetMonthsTest() { CampgroundSqlDAL testMonth = new CampgroundSqlDAL(connectionString); Assert.AreEqual("January", testMonth.GetMonths("1")); Assert.AreEqual("March", testMonth.GetMonths("3")); Assert.AreEqual("September", testMonth.GetMonths("9")); }
public ParkSystem(string connectionString) { this.ConnectionString = connectionString; campgroundDAL = new CampgroundSqlDAL(ConnectionString); campsiteDAL = new SiteSqlDAL(ConnectionString); parkDAL = new ParkSqlDAL(ConnectionString); reservationDAL = new ReservationSqlDAL(ConnectionString); }
public void GetCampgroundsTest() { CampgroundSqlDAL campgroundSqlDAL = new CampgroundSqlDAL(); string name = "Acadia"; List <Campground> test = campgroundSqlDAL.GetCampgrounds(name); Assert.IsNotNull(test); }
public void GetCampgroundsTest() { CampgroundSqlDAL dal = new CampgroundSqlDAL(ConnectionString); var campground = dal.GetCampgrounds(1); Assert.AreEqual(1, campground.Count); }
public void GetAvailability_ReturnsCount0Again1() { // Arrange CampgroundSqlDAL dal = new CampgroundSqlDAL(ConnectionString); IList <Campsite> campsite = dal.CampgroundAvailability(CampgroundId, new DateTime(2018, 07, 21), new DateTime(2018, 07, 22)); // Assert Assert.AreEqual(0, campsite.Count); }
public void GetCampgroundTest() { CampgroundSqlDAL dal = new CampgroundSqlDAL(connectionString); List <Campground> testList = dal.GetCampground(parkId); Assert.AreEqual(1, testList.Count()); Assert.AreEqual("TechElevator", testList[0].name); }
public void GetAllCampgroundsTest() { CampgroundSqlDAL dal = new CampgroundSqlDAL(connectionString); List <Campground> testList = dal.GetCampgrounds(1); Assert.AreEqual(1, testList[0].ParkId); Assert.AreEqual(4, testList.Count); Assert.IsNotNull(testList); }
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); } }
public void GetCampgroundInfo_Test() { CampgroundSqlDAL dal = new CampgroundSqlDAL(ConnectionString); Park testPark = new Park(1); dal.GetCampgroundInfo(testPark); Assert.AreEqual(1, testPark.Campgrounds.Count); }
private void ViewCampgrounds(Park selectedPark) { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Campground> campgrounds = campgroundDAL.GetCampgrounds(selectedPark); foreach (Campground campground in campgrounds) { Console.WriteLine(campground.ToString()); } }
//this method loads the Campground Dictionary for use in CLI public void PopulateCampgroundDictionary() { CampgroundSqlDAL campDal = new CampgroundSqlDAL(DatabaseConnection); List <Campground> campList = campDal.GetAllCampgrounds(); for (int i = 0; i < campList.Count; i++) { _campgrounds.Add(i, campList[i]); } }
public void PrintCampgroundsInParkSelectMenu(string parkId, string parkName) { while (true) { PrintHeader(); CampgroundSqlDAL dal = new CampgroundSqlDAL(connectionString); List <Campground> campgrounds = dal.GetAllAvailableCampgroundsInPark(parkId); if (campgrounds.Count > 0) { string campgroundId = "ID#"; string name = "Name:"; string openDate = "Open (mm):"; string closeDate = "Close (mm):"; string dailyFee = "Daily Fee:"; Console.WriteLine($"{parkName} National Park Campgrounds"); Console.WriteLine(); Console.WriteLine($"{campgroundId.PadRight(5)}{name.PadRight(35)}{openDate.PadRight(20)}{closeDate.PadRight(20)}{dailyFee.PadRight(10)}"); foreach (Campground campground in campgrounds) { Console.WriteLine($"#{campground.Campground_Id.ToString().PadRight(4)}{campground.Name.PadRight(35)}{numberMonth[campground.Open_From_Mm].PadRight(20)}{numberMonth[campground.Open_To_Mm].PadRight(20)}{campground.Daily_Fee.ToString("C").PadRight(10)}"); } } else { Console.WriteLine("**** NO AVAILABLE CAMPGROUNDS IN THIS PARK ****"); break; } Console.WriteLine(); Console.WriteLine("Select a Command"); Console.WriteLine("1) Search for Available Reservation"); Console.WriteLine("2) Return to Previous Screen"); string userInput = Console.ReadLine(); Console.Clear(); if (userInput != "1" && userInput != "2") { Console.Clear(); Console.WriteLine("Please enter a valid input"); Freeze(); } else if (userInput == "1") { SearchForCampgroundReservation(parkId, parkName); } else if (userInput == "2") { break; } } }
public void GetCampgroundInfoTest() { //Arrange CampgroundSqlDAL campgroundSqlDAL = new CampgroundSqlDAL(); //Act Campground campground = campgroundSqlDAL.GetCampgroundInfo("gramercy"); //Assert Assert.AreEqual(30.0, campground.Daily_Fee); }