Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (EmpresaEntities db = new EmpresaEntities())
            {
                if (id == null)
                {
                    oPersona = new Persona();
                }
                oPersona.Nombre   = name.Text;
                oPersona.Apellido = lastname.Text;
                oPersona.Genero   = gender.Text;
                oPersona.Correo   = mail.Text;
                oPersona.Telefono = Convert.ToInt32(phone.Text);

                if (id == null)
                {
                    db.Persona.Add(oPersona);
                }
                else
                {
                    db.Entry(oPersona).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();
                this.Close();
            }
        }
Ejemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            int?id;

            try
            {
                id = int.Parse(tabla.Rows[tabla.CurrentRow.Index].Cells[0].Value.ToString());
            }
            catch
            {
                id = null;
            }
            using (EmpresaEntities db = new EmpresaEntities())
            {
                Persona p = db.Persona.Find(id);
                db.Persona.Remove(p);
                db.SaveChanges();
            }
            Listar();
        }