static void Main(string[] args)
        {
            // This code reads the connection string from appsettings.json
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration    = builder.Build();
            string             connectionString = configuration.GetConnectionString("World");

            // TODO 00: Create a Model for Country to go with the City model we already have

            // TODO 01: Create a CountrySqlDAO class (GetCountries, GetCountries(continent), GetCountry(code))
            // TODO 01a: Create an ICountryDAO interface
            ICountryDAO countryDAO = new CountrySqlDAO(connectionString);

            // TODO 07: Create a CitySqlDAO class (GetCitiesByCountryCode)
            // TODO 07a: Create an ICityDAO interface


            // TODO 02b: Create a WorldDBMenu, passing in the country dao, and Run it
            WorldDBMenu menu = new WorldDBMenu(countryDAO);

            menu.Run();

            // Say goodbye to the user...
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.Write("Goodbye...");
            Thread.Sleep(1500);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // This code reads the connection string from appsettings.json
            // Add the connection string to appsettings.json and un-comment the following lines to read the configuration
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration    = builder.Build();
            string             connectionString = configuration.GetConnectionString("World");


            // TEMPORARY: DB EXAMPLE (vanilla, no DAO)
            //ReadCities();
            //return;

            ICountryDAO countryDAO = new CountrySqlDAO(connectionString);
            ICityDAO    cityDAO    = new CitySqlDAO(connectionString);

            // TODO 14a: Create a Model for CountryLanguage
            // TODO 14b: Create a CountryLanguageSqlDAO class (GetLanguages(string countryCode))
            // TODO 14c: Create an ICountryLanguageDAO interface
            ICountryLanguageDAO countryLanguageDAO = new CountryLanguageSqlDAO(connectionString);

            // Create a WorldDBMenu, passing in the country dao, and Run it
            WorldDBMenu menu = new WorldDBMenu(countryDAO, cityDAO, countryLanguageDAO);

            menu.Show();

            // Say goodbye to the user...
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.Write("Goodbye...");
            Thread.Sleep(1500);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // This code reads the connection string from appsettings.json
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration = builder.Build();

            // Get the connection string for the World database
            string connectionString = configuration.GetConnectionString("World");

            CitySqlDAO cityDAO = new CitySqlDAO(connectionString);

            List <City> cities = cityDAO.GetAllCities();

            foreach (City city in cities)
            {
                Console.WriteLine($"{city.Id,5} {city.Name,-40} {city.Population,12:N0} ");
            }
            Console.ReadLine();

            cities = cityDAO.GetCitiesForCountryCode("GBR");

            foreach (City city in cities)
            {
                Console.WriteLine($"{city.Id,5} {city.Name,-40} {city.Population,12:N0} ");
            }


            // GetAllCities(connectionString)

            // GetCitiesForCountry(connectionString, "USA");

            Console.ReadLine();
            return;

            // TODO: Create a City Model class

            // TODO: Create a City SQL DAO Class (GetCities, GetCitiesByCountryCode)

            // TODO: List the cities of the world

            // TODO: List the cities in a Country (code)

            // TODO: Add a City to the US

            // TODO: Create instances of DAOs to pass into the menus

            // TODO: Create a WorldDBMenu and Run it
            WorldDBMenu menu = new WorldDBMenu();

            menu.Run();

            // Say goodbye to the user...
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.Write("Goodbye...");
            Thread.Sleep(1500);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // This code reads the connection string from appsettings.json
            // TODO 03: Add the connection string to appsettings.json and un-comment the following lines to read the configuration
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration    = builder.Build();
            string             connectionString = configuration.GetConnectionString("World");


            // TEMPORARY: DB EXAMPLE (vanilla, no DAO)
            //ReadCities();
            //return;


            /* CREATED JUST TO TEST MENU
             * CountrySqlDAO dao = new CountrySqlDAO(connectionString);
             * List<Country> list = dao.GetCountries("Asia");
             *
             * Country country = dao.GetCountry("ZZZ");
             *
             * country = dao.GetCountry("USA");
             */

            // TODO 04a: Create a Model for Country to go with the City model we already have
            // TODO 04b: Create a CountrySqlDAO class (GetCountries, GetCountries(continent), GetCountry(code))
            // TODO 04c: Create an ICountryDAO interface


            // TODO 10: Create a CitySqlDAO class (GetCitiesByCountryCode)
            // TODO 10a: Create an ICityDAO interface

            // TODO 14a: Create a Model for CountryLanguage
            // TODO 14b: Create a CountryLanguageSqlDAO class (GetLanguages(string countryCode))
            // TODO 14c: Create an ICountryLanguageDAO interface
            ICountryDAO countryDAO = new CountrySqlDAO(connectionString);
            ICityDAO    cityDAO    = new CitySqlDAO(connectionString);

            // TODO 05b: Create a WorldDBMenu, passing in the country dao, and Run it
            WorldDBMenu menu = new WorldDBMenu(countryDAO, cityDAO);

            menu.Show();

            // Say goodbye to the user...
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.Write("Goodbye...");
            Thread.Sleep(1500);
        }
        static void Main(string[] args)
        {
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration    = builder.Build();
            string             connectionString = configuration.GetConnectionString("World");

            ICityDAO     cityDAO     = new CitySqlDAO(connectionString);
            ICountryDAO  countryDAO  = new CountrySqlDAO(connectionString);
            ILanguageDAO languageDAO = new LanguageSqlDAO(connectionString);

            WorldDBMenu menu = new WorldDBMenu(cityDAO, countryDAO, languageDAO);

            menu.Run();
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.Write("Goodbye...");
            Thread.Sleep(1500);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // TODO: This is how we load a configuration file and get the connection string
            IConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration    = builder.Build();
            string             connectionString = configuration.GetConnectionString("World");

            // TODO: This gets a custom value from the Config file
            bool useFileDAO = configuration.GetSection("DAO").GetValue <bool>("UseFileDAO", false);

            // TODO: Here, the Main method creates instances of DAOs which will be "injected" into the menu (CLI).
            ICityDAO     cityDAO;
            ICountryDAO  countryDAO;
            ILanguageDAO languageDAO;

            if (useFileDAO)
            {
                // TODO: This is a COMPLETELY different set of DAOs which implement the SAME interfaces
                cityDAO     = new CityFileDAO(@"..\..\..\City_Data.txt");
                countryDAO  = new CountryFileDAO(@"..\..\..\Country_Data.txt");
                languageDAO = new LanguageFileDAO(@"..\..\..\Language_Data.txt");
            }
            else
            {
                cityDAO     = new CitySqlDAO(connectionString);
                countryDAO  = new CountrySqlDAO(connectionString);
                languageDAO = new LanguageSqlDAO(connectionString);
            }

            // TODO: Here, we create the menu, and "inject" the DAOs we want to use
            WorldDBMenu menu = new WorldDBMenu(cityDAO, countryDAO, languageDAO);

            menu.Run();

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.Write("Goodbye...");
            Thread.Sleep(1500);
        }