Пример #1
0
        public void SaveReservationTest()
        {
            var park       = dal.GetParkList()[0];
            var campground = dal.GetCampgroundList(park)[0];
            var site       = dal.GetAllSitesInCampground(campground)[0];

            Reservation res = new Reservation
            {
                CreateDate = DateTime.Now,
                FromDate   = new DateTime(2019, 11, 2),
                ToDate     = new DateTime(2019, 11, 5),
                Name       = "Customer1",
                SiteID     = site.SiteID
            };

            res.ReservationID = dal.SaveReservation(res);

            var resList = dal.GetReservations(campground);

            Assert.AreEqual(2, resList.Count, "The reservation list should now have 2 entries.");
            Assert.AreNotEqual(0, res.ReservationID, "Reservation ID should not be 0.");
        }
Пример #2
0
        /// <summary>
        /// Shows available sites for user to reserve, reservation date must be after today's date.
        /// After information is confirmed, reservation confirmation number and info presented to user
        /// </summary>
        /// <param name="List (sites)">list of sites to display to user</param>
        /// <param name="arrival">first arrival date as input by user</param>
        /// <param name="departure">last arrival date as input by user</param>
        /// <param name="dailyFee">site cost per day from SQL DB</param>
        private void ChooseSite(List <Site> sites, DateTime arrival, DateTime departure, decimal dailyFee)
        {
            int     lengthOfStay = (departure - arrival).Days;
            decimal totalCost    = (lengthOfStay * dailyFee);

            bool exit = false;

            while (!exit)
            {
                Console.Clear();
                Console.WriteLine("Site No.".PadRight(20) + "Max Occup.".PadRight(20) +
                                  "Accessible".PadRight(20) + "RV Len".PadRight(20) + "Utility".PadRight(20) + "Cost");
                foreach (Site site in sites)
                {
                    string hasAccessible = site.Accessible ? "Yes" : "No";
                    string hasUtility    = site.Utilities ? "Yes" : "No";
                    string showRVLength  = site.MaxRVLength > 0 ? site.MaxRVLength.ToString() : "N/A";

                    Console.WriteLine($"{site.SiteNumber}".PadRight(20) + $"{site.MaxOccupancy}".PadRight(20) +
                                      $"{hasAccessible}".PadRight(20) +
                                      $"{showRVLength}".PadRight(20) + $"{hasUtility}".PadRight(20) + $"{totalCost:C}");
                }

                Reservation res = new Reservation();
                try
                {
                    int siteNum = GetInteger("Which site should be reserved (or 0 to cancel)? ");
                    if (siteNum == 0)
                    {
                        exit = true;
                    }
                    else
                    {
                        bool siteExists = false;
                        Site chosenSite = null;
                        foreach (Site site in sites)
                        {
                            if (siteNum == site.SiteNumber)
                            {
                                siteExists = true;
                                chosenSite = site;
                            }
                        }
                        if (siteExists)
                        {
                            Console.Write("\nWhat name should the reservation be under? ");
                            string userName = Console.ReadLine();

                            res.Name     = userName;
                            res.SiteID   = chosenSite.SiteID;
                            res.FromDate = arrival;
                            res.ToDate   = departure;

                            Console.WriteLine($"\nReservation ID: {dal.SaveReservation(res)} for {res.Name} at site {res.SiteID} from dates {res.FromDate.ToString().Substring(0, 10)}" +
                                              $" to {res.ToDate.ToString().Substring(0, 10)} ({lengthOfStay} days for {totalCost:C}).");
                            Console.ReadKey();
                            return;
                        }
                        else
                        {
                            Console.WriteLine("Please choose an available site from the list.");
                            Console.ReadKey();
                        }
                    }
                }
                catch (IndexOutOfRangeException) // Only caught if the selected campsite index is beyond the list size
                {
                    Console.WriteLine("Choose a number present in the campsite list.");
                }
            }
        }