Ejemplo n.º 1
0
 public void ReserveCampsite(int park_id, int campground_id, DateTime arrivalDate, DateTime departureDate)
 {
     while (true)
     {
         //Gets a list of available campsites
         SiteSqlDAL  siteSqlDal = new SiteSqlDAL(connectionString);
         List <Site> sites      = siteSqlDal.GetAvailableSites(campground_id, arrivalDate, departureDate);
         //Lets user know if no sites are available based on their search terms
         while (sites.Count == 0)
         {
             Console.WriteLine();
             Console.WriteLine("There are no available sites matching your search criteria.\nPress any Key to Continue.");
             Console.ReadKey();
             Console.Clear();
             SearchMenu(park_id);
         }
         //Create a reservation to pass into DAL methods, assign to and from times
         Reservation currentReservation = new Reservation();
         currentReservation.From_Date = arrivalDate;
         currentReservation.To_Date   = departureDate;
         //Get Number of days to multiply by daily cost of campground
         int numOfDays = (int)departureDate.Subtract(arrivalDate).TotalDays;
         //Displays all available sites based on search criteria
         Console.WriteLine();
         Console.WriteLine("Results Matching your Search Criteria:");
         Console.WriteLine();
         Console.Write("Site No.".PadRight(12));
         Console.Write("Max Occup.".PadRight(12));
         Console.Write("Accessible?".PadRight(15));
         Console.Write("Max RV Length".PadRight(18));
         Console.Write("Utility".PadRight(12));
         Console.WriteLine("Cost".PadRight(12));
         foreach (Site site in sites)
         {
             site.DisplaySite(numOfDays);
         }
         //Prompts user to enter their name and preferred site id
         Console.WriteLine();
         Console.Write("Which site should be reserved (enter 0 to cancel)? ");
         string siteReserved = Console.ReadLine().Trim();
         int    siteNumber;
         bool   isSiteEnteredAnInteger = int.TryParse(siteReserved, out siteNumber);
         currentReservation.Site_id = siteNumber;
         Console.Write("What name should the reservation be made under? ");
         currentReservation.Name = Console.ReadLine().Trim() + " Reservation";
         //Create a reservation for the selected site_id and reservation dates
         bool isReservationSuccessful = siteSqlDal.ReserveSite(currentReservation);
         if (isReservationSuccessful)
         {
             int reservation_id = siteSqlDal.GetReservationId(currentReservation);
             Console.WriteLine("\nThe reservation has been made and the confirmation ID is " + reservation_id);
             Console.ReadKey();
             Console.Clear();
             InitialMenu();
         }
         else
         {
             Console.WriteLine("Error: Your reservation was not made. Returning to home");
             Console.Clear();
             InitialMenu();
         }
     }
 }