Ejemplo n.º 1
0
        protected void btnSaveCountry_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtCountryName.Text) &&
                !string.IsNullOrEmpty(txtCountryLanguage.Text) &&
                fuPicture.HasFile &&
                lbContinents.SelectedIndex >= 0)
            {
                Byte[] imgByte = null;
                HttpPostedFile File = fuPicture.PostedFile;
                imgByte = new Byte[File.ContentLength];
                File.InputStream.Read(imgByte, 0, File.ContentLength);

                var db = new ContinentsEntities();

                var c = new Country();
                if (btnSaveCountry.CommandArgument != null)
                {
                    c = db.Countries.Find(int.Parse(btnSaveCountry.CommandArgument));
                    btnSaveCountry.CommandArgument = null;
                }
                if (c == null)
                {
                    c = new Country();
                }

                c.Name = Server.HtmlEncode(txtCountryName.Text);
                c.Language = Server.HtmlEncode(txtCountryLanguage.Text);
                c.Flag = imgByte;
                c.ContinentId = int.Parse(lbContinents.SelectedValue);

                db.Countries.AddOrUpdate(c);
                db.SaveChanges();
                grdCountries.DataBind();
            }
        }
Ejemplo n.º 2
0
 protected void btnSaveContinent_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtContinent.Text))
     {
         ContinentsEntities db = new ContinentsEntities();
         db.Continents.Add(new Continent()
         {
             Name = Server.HtmlEncode(txtContinent.Text)
         });
         db.SaveChanges();
         lbContinents.DataBind();
     }
 }