public string SaveCityInfo(Cities aCity) { if (!gateway.ISCityNameAlreadyExists(aCity)) { if (gateway.SaveCityInfo(aCity)>0) { return "City info saved Succesfully"; } else { return "City info saving failed"; } } else { return "City Name already exists"; } }
public int SaveCityInfo(Cities aCity) { string query = string.Format(@"INSERT INTO Cities VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", aCity.Name, aCity.About, aCity.No_Of_Dwellers, aCity.Location, aCity.Weather, aCity.Country_ID); SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return rowAffected; }
public bool ISCityNameAlreadyExists(Cities aCity) { bool isCityNameAlreadyExists = false; string query = string.Format("Select * From Cities Where Name='{0}'", aCity.Name); SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { isCityNameAlreadyExists = true; break; } reader.Close(); connection.Close(); return isCityNameAlreadyExists; }