Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Country country = new Country();

            country.Code           = textBoxCode.Text;
            country.Name           = textBoxName.Text;
            country.Continent      = textBoxContinent.Text;
            country.Region         = textBoxRegion.Text;
            country.SurfaceArea    = Convert.ToDouble(textBoxSurface.Text);
            country.InderYear      = Convert.ToDouble(textBoxIndep.Text);
            country.Population     = Convert.ToDouble(textBoxPopulation.Text);
            country.GovernmentForm = textBoxGov.Text;
            country.HeadOfState    = textBoxHead.Text;


            int arv = CountryDB.InsertNewCountry(country);

            if (arv != 0)
            {
                MessageBox.Show("Oli lisatud " + arv + " rida", "Valmis", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
                Form1 form = new Form1();
                form.Refresh();
            }
            else
            {
                MessageBox.Show("Lisamine ebaõnnestus", "Viga", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 //for new insert only
 public void InsertInCountry(string countryName, long zipCodeStart, long zipCodeEnd, bool isActive)
 {
     try
     {
         Countrydata objCountry = new Countrydata(countryName, zipCodeStart, zipCodeEnd, isActive);
         objCountry.Validate();
         CountryDB.InsertNewCountry(objCountry);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public IHttpActionResult Post([FromBody] Country country)
 {
     try
     {
         int newCode = CountryDB.InsertNewCountry(country.Description);
         country.CountryId = newCode;
         return(Created(new Uri(Request.RequestUri.AbsoluteUri + $"/GetCountryById/{ country.CountryId }"), country));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }