public int SaveCity(City city)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = @"INSERT INTO City VALUES('" + city.CityName + "','" + city.CityAbout + "','" + city.NoOfDwellers + "','" + city.Location + "','" + city.Weather + "'," + city.CountryID + ")";

            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            int roweffected = command.ExecuteNonQuery();
            connection.Close();

            return roweffected;
        }
        protected void submitButton_Click(object sender, EventArgs e)
        {
            
            string cityName = cityNameTextBox.Text;
            string cityAbout = cityAboutTextBox.Text.Replace("'", "''");
            int noOfDwellers = Convert.ToInt32(noOfDwellersTextBox.Text);
            string location = locationTextBox.Text;
            string weather = weatherTextBox.Text;
            int countryID = Convert.ToInt32(counrtyDropDownList.SelectedValue);

            City city=new City(cityName,cityAbout,noOfDwellers,location,weather,countryID);
            messageBoxLabel.Text = cityManager.SaveCity(city);

            cityWiseCountryGridView.DataSource = cityManager.GetCityWiseCountry();
            cityWiseCountryGridView.DataBind();

            TextClear();
        }
 public string SaveCity(City city)
 {
     City acity = cityGateway.IsExist(city);
     if (acity == null)
     {
        
         int roweffected = cityGateway.SaveCity(city);
         if (roweffected > 0)
         {
             return "Save Successfully";
         }
         else
         {
             return "Save Failed";
         }
     }
     else
     {
         return "City Name must be unique";
     }
     
 }
        public City IsExist(City city)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = "SELECT * FROM City WHERE CityName='" + city.CityName + "'";

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            City aCity = null;
            if (reader.HasRows)
            {
                reader.Read();
                aCity = new City();
                //aCity.CountryID = (int)reader["CountryID"];
                //aCity.CountryName = reader["CountryName"].ToString();
                //aCity.CountryAbout = reader["CountryAbout"].ToString();
            }
            reader.Close();
            connection.Close();

            return aCity;
        }