Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            CapitalCity c = obj as CapitalCity;

            if (c == null)
            {
                return(false);
            }
            return(this.Id == c.Id);
        }
Ejemplo n.º 2
0
        public object GetCountyAndItsCapitalCityDDetails(string countryName)
        {
            using (SQLiteCommand cmd = new SQLiteCommand($"SELECT *, COUNTRY.NAME as COUNTRY_NAME, CAPITALCITY.NAME as CITY_NAME FROM COUNTRY" +
                                                         $" JOIN CapitalCity ON COUNTRY.CAPITALCITY_ID = CapitalCity.ID WHERE COUNTRY.NAME = '{countryName}'", Connection))
            {
                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Country CurrentCountry = new Country
                        {
                            Id            = (int)reader["ID"],
                            Name          = (string)reader["NAME"],
                            SizeKm        = (int)reader["SIZE_KM"],
                            BirthYear     = (int)reader["BIRTH_YEAR"],
                            CapitalCityId = (int)reader["CAPITALCITY_ID"]
                        };

                        CapitalCity CurrentCity = new CapitalCity
                        {
                            Id          = (int)reader["ID"],
                            Name        = (string)reader["NAME"],
                            NumCitizens = (int)reader["NUMCITIZENS"],
                            CountryId   = (int)reader["COUNTRY_ID"]
                        };

                        var result = new
                        {
                            Country_Id          = CurrentCountry.Id,
                            Country_Name        = CurrentCountry.Name,
                            Capital_Name        = CurrentCity.Name,
                            Capital_NumCitizens = CurrentCity.NumCitizens,
                            Capital_Id          = CurrentCity.CountryId
                        };
                        return(result);
                    }
                }
            }
            return(null);
        }