Ejemplo n.º 1
0
        public List<Country> GetAllCountries()
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = "SELECT * FROM Country ORDER BY CountryName ASC";

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            List<Country> countries = new List<Country>();
            while (reader.Read())
            {
                int id = Convert.ToInt32(reader["Id"].ToString());
                string countryName = reader["CountryName"].ToString();
                string countryAbout = reader["CountryAbout"].ToString();

                Country country = new Country();
                country.CountryID = id;
                country.CountryName = countryName;
                country.CountryAbout = countryAbout;

                countries.Add(country);
            }
            reader.Close();
            connection.Close();
            return countries;
        }
Ejemplo n.º 2
0
        public Country IsExistConCountry(Country aCountry)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string query = "SELECT * FROM Country WHERE CountryName='" + aCountry.CountryName + "'";

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            Country country = null;
            while (reader.Read())
            {

                string countryName = reader["CountryName"].ToString();
                string countryAbout = reader["CountryAbout"].ToString();

                country = new Country();
                country.CountryName = countryName;
                country.CountryAbout = countryAbout;

            }
            reader.Close();
            connection.Close();
            return country;

        }
Ejemplo n.º 3
0
        public bool AddCountry(Country country)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            string quiry = "INSERT INTO Country VALUES('" + country.CountryName + "','" + country.CountryAbout + "')";
            SqlCommand command = new SqlCommand(quiry, connection);
            connection.Open();
            int rowAffectedCount = command.ExecuteNonQuery();

            if (rowAffectedCount > 0)
            {
                return true;

            }
            return false;

        }
Ejemplo n.º 4
0
        public string AddCountry(Country country)
        {
            Country aCountry = gateway.IsExistConCountry(country);

            if (aCountry == null)
            {
                gateway.AddCountry(country);
                return "Country added successfully.";
            }

            else if (aCountry != null)
            {
                return "Exist country.";
            }
            else
            {
                return "No data has been Added.";
            }

        }
 protected void saveButton_Click(object sender, EventArgs e)
 {
     Country country = new Country(nameTextBox.Text, aboutTextBox.Text);
     showMessageLable.Text = manager.AddCountry(country);
     LoadAllCountries();
 }