public void FindAvailableSitesTest()
        {
            const int _campgroundId  = 1;
            DateTime  _arrivalDate   = Convert.ToDateTime("03/01/2019");
            DateTime  _departureDate = Convert.ToDateTime("03/03/2019");
            Site      _expectedSite1 = new Site(1, 1, 1, 6, 0, 0, 0);
            Site      _expectedSite2 = new Site(2, 1, 2, 6, 0, 0, 0);
            Site      _expectedSite3 = new Site(3, 1, 3, 6, 0, 0, 0);
            Site      _expectedSite4 = new Site(6, 1, 6, 6, 1, 0, 1);
            Site      _expectedSite5 = new Site(7, 1, 7, 6, 0, 20, 0);

            Dictionary <int, Site> _expectedSites = new Dictionary <int, Site>
            {
                { 1, _expectedSite1 },
                { 2, _expectedSite2 },
                { 3, _expectedSite3 },
                { 6, _expectedSite4 },
                { 7, _expectedSite5 }
            };

            Dictionary <int, Site> _sites = _db.FindAvailableSites(_campgroundId, _arrivalDate, _departureDate);

            foreach (Site site in _sites.Values)
            {
                Assert.AreEqual(_expectedSites[site.SiteNum].Id, site.Id, "invalid Id");
                Assert.AreEqual(_expectedSites[site.SiteNum].CampgroundId, site.CampgroundId, "campground");
                Assert.AreEqual(_expectedSites[site.SiteNum].SiteNum, site.SiteNum, "site");
                Assert.AreEqual(_expectedSites[site.SiteNum].SiteOccupancy, site.SiteOccupancy, "occupancy");
                Assert.AreEqual(_expectedSites[site.SiteNum].Accessible, site.Accessible, "accessible");
                Assert.AreEqual(_expectedSites[site.SiteNum].DisplayAccessible, site.DisplayAccessible);
                Assert.AreEqual(_expectedSites[site.SiteNum].MaxRVLength, site.MaxRVLength, "rv length");
                Assert.AreEqual(_expectedSites[site.SiteNum].DisplayMaxRVLength, site.DisplayMaxRVLength);
                Assert.AreEqual(_expectedSites[site.SiteNum].Utilities, site.Utilities, "Utilities");
                Assert.AreEqual(_expectedSites[site.SiteNum].DisplayUtilities, site.DisplayUtilities);
            }
        }
Exemplo n.º 2
0
        private void SearchForCampgroundReservation(int parkId, Dictionary <int, Campground> campgrounds)
        {
            bool quit = false;

            while (!quit)
            {
                Console.Clear();
                DisplayCampgroundsByPark(parkId, campgrounds);

                try
                {
                    //Need to add verification
                    Console.WriteLine("\nWhich campground (enter 0 to cancel)?");
                    string userCampgroundChoiceString = Console.ReadLine();
                    int    userCampgroundChoice       = int.Parse(userCampgroundChoiceString);

                    Console.WriteLine("What is the arrival date? (MM/DD/YYYY)");
                    string   arrivalDateString = Console.ReadLine();
                    DateTime arrivalDate       = Convert.ToDateTime(arrivalDateString);

                    Console.WriteLine("What is the departure date? (MM/DD/YYYY)");
                    string   departureDateString = Console.ReadLine();
                    DateTime departureDate       = Convert.ToDateTime(departureDateString);

                    if (arrivalDate > departureDate)
                    {
                        throw new Exception();
                    }

                    if (userCampgroundChoice == 0)
                    {
                        quit = true;
                    }
                    else
                    {
                        Dictionary <int, Site> sites = _db.FindAvailableSites(userCampgroundChoice, arrivalDate, departureDate);

                        if (sites.Count == 0)
                        {
                            Console.Clear();
                            Console.WriteLine("No sites are avaible for the given dates");
                            Console.WriteLine("Press any key to return to the previous screen...");
                            Console.ReadKey();
                            break;
                        }

                        Console.WriteLine("Results Matching Your Search Criteria");
                        Console.WriteLine("Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(12) + "Max RV Length".PadRight(15) + "Utility".PadRight(10) + "Cost");

                        foreach (var site in sites)
                        {
                            decimal costOfReservation = campgrounds[site.Value.CampgroundId].DailyFee *
                                                        (decimal)(departureDate - arrivalDate).TotalDays;

                            Console.WriteLine($"{site.Value.SiteNum}".PadRight(10) + $"{site.Value.SiteOccupancy}".PadRight(12) +
                                              $"{site.Value.DisplayAccessible}".PadRight(12) + $"{site.Value.DisplayMaxRVLength}".PadRight(15) +
                                              $"{site.Value.DisplayUtilities}".PadRight(10) + costOfReservation.ToString("C"));
                        }
                        Console.WriteLine("Which site should be reserved (enter 0 to cancel)?");
                        string userChoice = Console.ReadLine();


                        try
                        {
                            int siteNum = int.Parse(userChoice);

                            if (sites.ContainsKey(siteNum))
                            {
                                Console.WriteLine("What name should the reservation be made under?");
                                string reservationName   = Console.ReadLine();
                                int    reservationNumber = _db.AddReservation(sites[siteNum].Id, reservationName, arrivalDate, departureDate);
                                Console.WriteLine($"\nThe reservation has been made and the confirmation id is {reservationNumber}");
                                Console.WriteLine($"\nPress any key to return to the campgrounds screen...");
                                Console.ReadKey();
                                quit = true;
                            }
                            else if (siteNum == 0)
                            {
                                quit = true;
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }
                        catch
                        {
                            Console.Clear();
                            Console.WriteLine("Please enter only valid command");
                            Console.Write("Press any key to return to the campgrounds screen...");
                            Console.ReadKey();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Something went wrong!");
                    Console.ReadKey();
                }
            }
        }
Exemplo n.º 3
0
        private void CreateReservation(int userCampgroundChoice, Dictionary <int, Campground> campgrounds)
        {
            bool quit = false;

            while (!quit)
            {
                Console.WriteLine("What is the arrival date? (MM/DD/YYYY)");
                string   arrivalDateString = Console.ReadLine();
                DateTime arrivalDate       = parseDateFromString(arrivalDateString);

                Console.WriteLine("What is the departure date? (MM/DD/YYYY)");
                string   departureDateString = Console.ReadLine();
                DateTime departureDate       = parseDateFromString(departureDateString);
                try
                {
                    Dictionary <int, Site> sites = new Dictionary <int, Site>();
                    if (arrivalDate >= DateTime.Now.Date && arrivalDate < departureDate)
                    {
                        sites = _db.FindAvailableSites(userCampgroundChoice, arrivalDate, departureDate);
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("The arrival and/or departure dates are invalid.");
                        Console.WriteLine("Would you like to enter a new set of dates? (Y) for yes or (N) for no");
                        string reenterDateChoice = Console.ReadLine();

                        if (reenterDateChoice.ToLower() == "y")
                        {
                            break;
                        }
                        else if (reenterDateChoice.ToLower() == "n")
                        {
                            quit = true;
                            break;
                        }
                        else
                        {
                            throw new InvalidYesNoException("Your input was invalid. Please enter (Y) for yes or (N) for no");
                        }
                    }


                    if (sites.Count == 0)
                    {
                        Console.Clear();
                        Console.WriteLine("No sites are available for the given dates");
                        Console.WriteLine("Would you like to enter a new set of dates? (Y) for yes or (N) for no");
                        string reenterDateChoice = Console.ReadLine();

                        if (reenterDateChoice.ToLower() == "y")
                        {
                            break;
                        }
                        else if (reenterDateChoice.ToLower() == "n")
                        {
                            quit = true;
                            break;
                        }
                        else
                        {
                            throw new InvalidYesNoException("Your input was invalid. Please enter (Y) for yes or (N) for no");
                        }
                    }


                    Console.WriteLine("Results Matching Your Search Criteria");
                    Console.WriteLine("Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(12) + "Max RV Length".PadRight(15) + "Utility".PadRight(10) + "Cost");


                    foreach (var site in sites)
                    {
                        decimal costOfReservation = campgrounds[site.Value.CampgroundId].DailyFee *
                                                    (decimal)(departureDate - arrivalDate).TotalDays;

                        Console.WriteLine($"{site.Value.SiteNum}".PadRight(10) + $"{site.Value.SiteOccupancy}".PadRight(12) +
                                          $"{site.Value.DisplayAccessible}".PadRight(12) + $"{site.Value.DisplayMaxRVLength}".PadRight(15) +
                                          $"{site.Value.DisplayUtilities}".PadRight(10) + costOfReservation.ToString("C"));
                    }
                    Console.WriteLine("Which site should be reserved (enter 0 to cancel)?");

                    string userChoice = Console.ReadLine();
                    int    siteNum    = parseUserChoiceFromString(userChoice);

                    if (sites.ContainsKey(siteNum))
                    {
                        Console.WriteLine("What name should the reservation be made under?");
                        string reservationName   = Console.ReadLine();
                        int    reservationNumber = _db.AddReservation(sites[siteNum].Id, reservationName, arrivalDate, departureDate);
                        Console.WriteLine($"\nThe reservation has been made.\nThe confirmation id is {reservationNumber}");
                        Console.WriteLine($"\nPress any key to return to the campgrounds screen...");
                        Console.ReadKey();
                        quit = true;
                    }
                    else if (siteNum == 0)
                    {
                        quit = true;
                    }
                    else
                    {
                        throw new OnlyValidChoiceException("Please enter only valid site.");
                    }
                }
                catch (Exception ex)
                {
                    Console.Clear();
                    Console.WriteLine(ex.Message);
                    Console.Write("Press any key to return to the campgrounds screen...");
                    quit = true;
                    Console.ReadKey();
                }
            }
        }