Example #1
0
 private void SetCountryLanguage(CountryLanguage language, NpgsqlDataReader dr)
 {
     language.CountryCode = dr[0].ToString();
     language.Name = dr[4].ToString();
     language.IsOfficial = (bool)dr[5];
     language.PercentageUse = double.Parse(dr[6].ToString());
 }
Example #2
0
        public List<CountryViewModel> GetCountries(string countryQuery = "")
        {
            List<CountryViewModel> countries = new List<CountryViewModel>();

            try
            {
                PsgsqlConnection.Open();
                NpgsqlCommand command = new NpgsqlCommand(string.IsNullOrEmpty(countryQuery) ? Resources.getCountriesQuery : countryQuery, PsgsqlConnection);
                NpgsqlDataReader dr = command.ExecuteReader();
                while (dr.Read())
                {
                    CountryLanguage language = new CountryLanguage();
                    CountryViewModel country = new CountryViewModel();
                    if (countries.Exists(item => item.Code.Equals(dr[0].ToString())))
                    {
                        SetCountryLanguage(language, dr);
                        countries.Where(item => item.Code.Equals(dr[0].ToString())).Single().Languages.Add(language);
                    }
                    else
                    {
                        List<CountryLanguage> LanguagesList = new List<CountryLanguage>();
                        if (!dr[4].GetType().Name.Equals("DBNull"))
                        {
                            SetCountryLanguage(language, dr);
                            LanguagesList.Add(language);
                        }
                        SetCountry(country, dr, LanguagesList);
                        countries.Add(country);
                    }
                }
                dr.Close();
            }
            finally
            {
                PsgsqlConnection.Close();
            }

            return countries;
        }