Ejemplo n.º 1
0
        protected void saveCityButton_Click1(object sender, EventArgs e)
        {
            City aCity = new City();
            aCity.Name = Request.Form["cityNameTextBox"];
            aCity.About = Request.Form["cityAboutTextarea"];
            aCity.Dwellers = double.Parse(Request.Form["dwellersTextBox"]);
            aCity.Location = Request.Form["locationTextBox"];
            aCity.Weather = Request.Form["weatherTextarea"];
            aCity.CountryId = Convert.ToInt32(countryDropDownList.SelectedItem.Value);

            string message = cityManager.SaveCity(aCity);

            messageLabel.Text = message;
            LoadAllCityInGridView();
        }
Ejemplo n.º 2
0
 public string SaveCity(City aCity)
 {
     if (cityGateway.IsCityNameExists(aCity.Name))
     {
         return "City name already Exists";
     }
     else
     {
         if (cityGateway.SaveCity(aCity))
         {
             return "City name successfully save";
         }
         else
         {
             return "Save Failed";
         }
     }
 }
Ejemplo n.º 3
0
        public List<City> GetAllCity()
        {
            string allCityQuery = "SELECT CityName, Dwellers, CountryName FROM tbl_city JOIN tbl_country ON tbl_country.id=tbl_city.CountryId ORDER BY CityName ASC ";
            sqlConnection.Open();
            sqlCommand.CommandText = allCityQuery;
            SqlDataReader reader = sqlCommand.ExecuteReader();

            List<City> allCityList = new List<City>();

            while (reader.Read())
            {
                City aCity = new City();

                aCity.Name = reader["CityName"].ToString();
                aCity.Dwellers = int.Parse(reader["Dwellers"].ToString());
                aCity.Country = reader["CountryName"].ToString();

                allCityList.Add(aCity);
            }
            reader.Close();
            sqlConnection.Close();

            return allCityList;
        }
Ejemplo n.º 4
0
        public bool SaveCity(City aCity)
        {
            string insertSQL;
            insertSQL = "INSERT INTO tbl_city (";
            insertSQL += "CityName, AboutCity, Dwellers, Location, Weather, CountryId) ";
            insertSQL += "VALUES (";
            insertSQL += "@name, @about, @dwellers, @location, @weather, @ciuntryid)";

            sqlConnection.Open();
            sqlCommand.CommandText = insertSQL;
            sqlCommand.Parameters.AddWithValue("@name", aCity.Name);
            sqlCommand.Parameters.AddWithValue("@about", aCity.About);
            sqlCommand.Parameters.AddWithValue("@dwellers", aCity.Dwellers);
            sqlCommand.Parameters.AddWithValue("@location", aCity.Location);
            sqlCommand.Parameters.AddWithValue("@weather", aCity.Weather);
            sqlCommand.Parameters.AddWithValue("@ciuntryid", aCity.CountryId);

            int saveRowAffected = sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();

            if (saveRowAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }