Ejemplo n.º 1
0
        /// <summary>
        /// SearchCampSites method calls the GetSites method from the SiteSqlDAL and pass it to a list which we then call in the if statement
        /// and if count > 0 we then print out the appropriate response and we again use the foreach loop to print out the results from the
        /// database. we also use the CLIhelper again to take in the user input.
        /// </summary>
        private void SearchCampSites()
        {
            int      campgroundId = CLIHelper.GetInteger("Which campground (enter 0 to cancel)? ");
            DateTime startDate    = CLIHelper.GetDateTime("What is the arrival date? (YYYY/MM/DD): ");
            DateTime endDate      = CLIHelper.GetDateTime("What is the departure date? (YYYY/MM/DD): ");

            //double totalDays = (endDate - startDate).TotalDays;

            SiteSqlDAL  dal      = new SiteSqlDAL(DatabaseConnection);
            List <Site> allSites = dal.GetSites(campgroundId, startDate, endDate);

            if (allSites.Count > 0)
            {
                Console.WriteLine();
                Console.WriteLine("Site Number".PadRight(14) + "Max Occupancy".PadRight(15) + "Accessible".PadRight(15) + "Max RV Length".PadRight(17) + "Utilities".PadRight(16) + "Cost".PadRight(15));
                Console.WriteLine();

                allSites.ForEach(theseSites =>
                {
                    Console.WriteLine(theseSites);
                });
            }
            else
            {
                Console.WriteLine("There was an error with your inputs...");
            }
        }
Ejemplo n.º 2
0
        public void GetSitesTest()
        {
            SiteSqlDAL dal = new SiteSqlDAL(ConnectionString);

            var site = dal.GetSites(1, 1);

            Assert.AreEqual(1, site.Count);
        }
Ejemplo n.º 3
0
        public void GetAllSitesTest()
        {
            SiteSqlDAL  testSite = new SiteSqlDAL(connectionString);
            List <Site> siteList = testSite.GetSites(1, System.DateTime.Now, System.DateTime.Today);

            Assert.AreEqual(2, siteList[1].SiteId);
            Assert.AreEqual(0, siteList[3].MaxRvLength);
            Assert.AreEqual("No", siteList[0].Accessible);
        }
        public void GetSites_GetsSites()
        {
            // Arrange
            SiteSqlDAL   SSDal = new SiteSqlDAL(ConnectionString);
            IList <Site> sites = new List <Site>();

            // Act
            sites = SSDal.GetSites(1, "10/20/2018", "10/25/2018");

            // Assert
            Assert.AreEqual(1, sites.Count);
        }
        private void GetSites(int campgroundId, string fromDate, string toDate)
        {
            ISiteDAL     sitedal      = new SiteSqlDAL(DatabaseConnectionString.DatabaseString);
            IList <Site> sites        = sitedal.GetSites(campgroundId, fromDate, toDate);
            string       siteNum      = "Site No.";
            string       maxOccupancy = "Max Occup.";
            string       accessible   = "Accessible?";
            string       rvLength     = "RV Length";
            string       utility      = "Utility";
            string       cost         = "Cost";
            DateTime     fromDateTime = DateTime.Parse(fromDate);
            DateTime     toDateTime   = DateTime.Parse(toDate);
            decimal      numDaysStay  = (decimal)(toDateTime - fromDateTime).TotalDays;



            Console.WriteLine($"{siteNum.PadRight(12)} {maxOccupancy.PadRight(13)} {accessible.PadRight(19)} {rvLength.PadRight(18)} {utility.PadRight(12)} {cost} ");
            for (int i = 0; i < sites.Count; i++)
            {
                if (sites[i].Accessible == 0)
                {
                    accessible = "No";
                }
                else
                {
                    accessible = "Yes";
                }

                if (sites[i].MaxRvLength == 0)
                {
                    rvLength = "N/A";
                }
                else
                {
                    rvLength = sites[i].MaxRvLength.ToString();
                }

                if (sites[i].Utilities == 1)
                {
                    utility = "Yes";
                }

                else
                {
                    utility = "N/A";
                }


                Console.WriteLine($"{sites[i].SiteNumber.ToString().PadRight(12)} {sites[i].MaxOccupancy.ToString().PadRight(14)}" +
                                  $"{accessible.PadRight(19)} {rvLength.PadRight(18)} {utility.PadRight(12)} {String.Format("{0:C2}", campgrounds[campgroundId].DailyFee * numDaysStay)}");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Displays the sites available at the selected campground at the selected park
        /// </summary>
        /// <param name="parkId"></param>
        /// <param name="campgroundId"></param>
        /// <returns>Site number selected by user</returns>
        private int[] DisplayAvailableSites(int parkId, int campgroundId)
        {
            int siteNumber = 0;
            int siteId     = 0;

            int[] sitePair = new int[2] {
                siteId, siteNumber
            };
            while (true)
            {
                SiteSqlDAL   dal   = new SiteSqlDAL(DatabaseConnection);
                IList <Site> sites = dal.GetSites(parkId, campgroundId);

                if (sites.Count > 0)
                {
                    Console.WriteLine("Site Number".ToString().PadRight(15) + "Max. Occupancy".ToString().PadRight(15) + "Accessible?".ToString().PadRight(15) + "Max RV Length".ToString().PadRight(15) + "Utility".ToString().PadRight(15) + "Cost".ToString());
                    foreach (Site site in sites)
                    {
                        Console.WriteLine(site.SiteNumber.ToString().PadRight(15) + site.MaxOccupancy.ToString().PadRight(15) + site.IsAccessible.ToString().PadRight(15) + site.MaxRVLength.ToString().PadRight(15) + site.HasUtilities.ToString().PadRight(15) + site.DailyFee.ToString("C2"));
                    }
                }
                else
                {
                    Console.WriteLine("**** SOLD TO PRIVATE CORPORATION-TEDDY ROOSEVELT SPINNING IN GRAVE ****");
                }
                Console.WriteLine();
                Console.Write("Which site should be reserved (enter 0 to cancel)? ");

                siteNumber = CLIHelper.GetInteger(Console.ReadLine());
                bool validSite = false;
                foreach (var site in sites)
                {
                    if (siteNumber == site.SiteNumber)
                    {
                        validSite   = true;
                        siteId      = site.SiteId;
                        sitePair[0] = siteId;
                        sitePair[1] = site.SiteNumber;
                        break;
                    }
                }
                if (validSite || siteNumber == 0)
                {
                    break;
                }
            }
            return(sitePair);
        }