Ejemplo n.º 1
0
        // Edit New Item
        private void editMenu_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(CS))
            {
                con.Open();

                try
                {
                    Reset();
                    EditPanel.Visible = true;
                    viewPanel.Visible = false;
                    saveInfo.Text     = "UPDATE";

                    //COUNTRYID = Convert.ToInt32(dgvCountry.SelectedRows[0].Cells[0].Value);

                    textName.Text = dgvCountry.SelectedRows[0].Cells[1].Value.ToString();
                    textDes.Text  = dgvCountry.SelectedRows[0].Cells[2].Value.ToString();
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            DataTable dt = CountryDA.GetCountryById(COUNTRYID);

            if (dt != null && dt.Rows.Count > 0)
            {
                textName.Text = dt.Rows[0]["CountryName"].ToString();
                textDes.Text  = dt.Rows[0]["Description"].ToString();
            }
        }
Ejemplo n.º 2
0
        public IActionResult GetCountriesById(int countryId)
        {
            List <CountryModel> countriesById = new List <CountryModel>();
            var dt = CountryDA.GetCountryById(countryId);

            foreach (DataRow dataRow in dt.Rows)
            {
                CountryModel countryModel = new CountryModel();
                countryModel.CountryId   = Convert.ToInt32(dataRow["CountryId"]);
                countryModel.CountryName = dataRow["CountryName"].ToString();
                countryModel.Description = dataRow.IsNull("Description") ? null : dataRow["Description"].ToString();
                countriesById.Add(countryModel);
            }
            return(Ok(countriesById));
        }