Example #1
0
        public static void ShowAllCountriesFromDB(CountryDBContext _db)
        {
            ///<summary>
            ///Метод выводит всю информацию из базы
            ///в алфавитном порядке по странам
            /// </summary>
            var countries = from country in _db.Countries
                            orderby country.Name
                            join city in _db.Cities on country.CityId equals city.Id
                            join region in _db.Regions on country.RegionId equals region.Id
                            select new
            {
                Name        = country.Name,
                City        = city.Name,
                Region      = region.Name,
                Area        = country.Area,
                Population  = country.Population,
                CallingCode = country.CallingCode
            };

            foreach (var singleCountry in countries)
            {
                Console.WriteLine("----------------------------------------");
                Console.WriteLine($"Country name: {singleCountry.Name}");
                Console.WriteLine($"Country capital: {singleCountry.City}");
                Console.WriteLine($"Country calling code: {singleCountry.CallingCode}");
                Console.WriteLine($"Country area: {singleCountry.Area}");
                Console.WriteLine($"Country population: {singleCountry.Population}");
                Console.WriteLine($"Country region: {singleCountry.Region}");
                Console.WriteLine("----------------------------------------");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                using (var _db = new CountryDBContext())
                {
                    Info.Greeting();

                    var number = Console.ReadLine();

                    while (number != "4")
                    {
                        switch (number)
                        {
                        case "1":
                            Console.WriteLine("1");
                            Info.ShowAllCountriesFromDB(_db);
                            break;

                        case "2":
                            Console.WriteLine("2");
                            Console.WriteLine("Введите название страны на английском языке:");
                            var country = Console.ReadLine();
                            Query.Querying(_db, country);
                            break;

                        case "3":
                            Query.AddingToDB(_db);
                            break;

                        default:
                            Console.WriteLine("Выберите 1, 2, 3 или 4!");
                            break;
                        }
                        Info.Greeting();
                        number = Console.ReadLine();
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #3
0
        public static void Querying(CountryDBContext _db, string countryName)
        {
            ///<summary>
            ///метод добавляет в базу информацию,
            ///полученную из интернета
            /// </summary>


            if (Networking.Request(countryName, out dictionaries))
            {
                foreach (var dictionary in dictionaries)
                {
                    Info.ShowInfo(dictionary);

                    var city = Build.NewCity(dictionary);

                    var region = Build.NewRegion(dictionary);

                    var country = Build.NewCountry(dictionary);

                    if (_db.Cities.FirstOrDefault(c => c.Name == city.Name) == null)
                    {
                        CountryDBContext.AddToDbCity(_db, city);
                    }

                    if (_db.Regions.FirstOrDefault(c => c.Name == region.Name) == null)
                    {
                        CountryDBContext.AddToDbRegion(_db, region);
                    }

                    if (_db.Countries.FirstOrDefault(c => c.Name == country.Name) == null)
                    {
                        CountryDBContext.AddToDbCountry(_db, country, region, city);
                    }
                }
            }
            else
            {
                Console.WriteLine("Не удалось получить ответ");
            }
        }
Example #4
0
 public CountryRepository(CountryDBContext context)
 {
     _context = context;
 }
Example #5
0
        public static void AddingToDB(CountryDBContext _db)
        {
            ///<summary>
            ///метод реализует добавление информации в базу вручную
            /// </summary>

            Console.WriteLine("Введите название страны на английском языке:");
            var countryName = Console.ReadLine();

            Console.WriteLine("Введите название столицы на английском языке:");
            var cityName = Console.ReadLine();

            Console.WriteLine("Введите название региона(Европа, Азия и т.д.) на английском языке:");
            var regionName = Console.ReadLine();

            string callingCode;
            int    callingCodeNumber;

            do
            {
                Console.WriteLine("Введите телефонный код страны:");
                callingCode = Console.ReadLine();
            }while (!int.TryParse(callingCode, out callingCodeNumber));

            string citizenPopulation;
            int    sitizenPopulationNumber;

            do
            {
                Console.WriteLine("Введите количество жителей страны:");
                citizenPopulation = Console.ReadLine();
            }while (!int.TryParse(citizenPopulation, out sitizenPopulationNumber));

            string areaSize;
            double areaSizeNumber;

            do
            {
                Console.WriteLine("Введите площадь страны:");
                areaSize = Console.ReadLine();
            }while (!double.TryParse(areaSize, out areaSizeNumber));

            var city = Build.NewCity(cityName);

            var region = Build.NewRegion(regionName);

            var country = Build.NewCountry(countryName,
                                           callingCode,
                                           areaSizeNumber,
                                           sitizenPopulationNumber);

            if (_db.Cities.FirstOrDefault(c => c.Name == city.Name) == null)
            {
                CountryDBContext.AddToDbCity(_db, city);
            }

            if (_db.Regions.FirstOrDefault(c => c.Name == region.Name) == null)
            {
                CountryDBContext.AddToDbRegion(_db, region);
            }

            if (_db.Countries.FirstOrDefault(c => c.Name == country.Name) == null)
            {
                CountryDBContext.AddToDbCountry(_db, country, region, city);
            }
        }
Example #6
0
 public SettlementsController(CountryDBContext context)
 {
     _context = context;
 }
Example #7
0
 public CountryController(ICountryRepository countryRepository, IMapper mapper, CountryDBContext context)
 {
     _context           = context;
     _countryRepository = countryRepository;
     _mapper            = mapper;
 }
Example #8
0
 public DistrictsController(CountryDBContext context)
 {
     _context = context;
 }
Example #9
0
 public RegionsController(CountryDBContext context)
 {
     _context = context;
 }