コード例 #1
0
        public ActionResult Editar(tablaViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (crudEntities db = new crudEntities())
                    {
                        var oTabla = db.tabla.Find(model.Id);
                        oTabla.correo           = model.Correo;
                        oTabla.fecha_nacimiento = model.Fecha_Nacimiento;
                        oTabla.nombre           = model.Nombre;

                        db.Entry(oTabla).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(Redirect("/tabla"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #2
0
        public ActionResult Editar(PersonaViewModel personaVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (crudEntities db = new crudEntities())
                    {
                        var persona = db.personaprueba.Find(personaVM.idPersona);
                        persona.nombre      = personaVM.nombre;
                        persona.edad        = personaVM.edad;
                        persona.descripcion = personaVM.descripcion;

                        db.Entry(persona).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(Redirect("/Persona/Index"));
                }

                return(View(personaVM));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #3
0
        public ActionResult Nuevo(tablaViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (crudEntities db = new crudEntities())
                    {
                        var oTabla = new tabla();
                        oTabla.correo           = model.Correo;
                        oTabla.fecha_nacimiento = model.Fecha_Nacimiento;
                        oTabla.nombre           = model.Nombre;

                        db.tabla.Add(oTabla);
                        db.SaveChanges();
                    }
                    return(Redirect("/tabla"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #4
0
        public ActionResult Nuevo(PersonaViewModel personaVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (crudEntities db = new crudEntities())
                    {
                        var persona = new personaprueba();
                        persona.nombre      = personaVM.nombre;
                        persona.edad        = personaVM.edad;
                        persona.descripcion = personaVM.descripcion;

                        db.personaprueba.Add(persona);
                        db.SaveChanges();
                    }
                    return(Redirect("/Persona/Index"));
                }

                return(View(personaVM));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #5
0
ファイル: PersonaForm.cs プロジェクト: pintoderian/CrudWForms
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (crudEntities db = new crudEntities())
            {
                if (id == null)
                {
                    persona = new personas();
                }

                int edad_id = int.Parse(edadesList.SelectedValue.ToString());
                persona.nombre  = textNombre.Text;
                persona.edad_id = edad_id;
                persona.fecha   = textFecha.Value;

                if (id == null)
                {
                    db.personas.Add(persona);
                }
                else
                {
                    db.Entry(persona).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();

                this.Close();
            }
        }
コード例 #6
0
 public ActionResult Eliminar(int Id)
 {
     using (crudEntities db = new crudEntities())
     {
         var oTabla = db.tabla.Find(Id);
         db.tabla.Remove(oTabla);
         db.SaveChanges();
     }
     return(Redirect("/tabla"));
 }
コード例 #7
0
 public ActionResult Eliminar(int id)
 {
     using (crudEntities db = new crudEntities())
     {
         var persona = db.personaprueba.Find(id);
         db.personaprueba.Remove(persona);
         db.SaveChanges();
     }
     return(Redirect("~/Persona/Index"));
 }
コード例 #8
0
ファイル: Form1.cs プロジェクト: Firuze-rustemli/CRUD-db
        //add
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string add_name = boxName.Text;

            if (add_name.Length > 0)
            {
                Course crs = new Course();
                crs.name = add_name;

                db.Course.Add(crs);
                db.SaveChanges();
                MessageBox.Show("added");
                boxName.Clear();
                getData();
            }
            else
            {
                MessageBox.Show("Errorrrr");
            }
        }
コード例 #9
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            int?id = GetId();

            using (crudEntities db = new crudEntities())
            {
                personas persona = db.personas.Find(id);
                db.personas.Remove(persona);
                db.SaveChanges();
            }
            Refrescar();
        }
コード例 #10
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            using (crudEntities db = new crudEntities())
            {
                if (id == null)
                {
                    edad = new edades();
                }

                edad.nro = textNro.Text;
                if (id == null)
                {
                    db.edades.Add(edad);
                }
                else
                {
                    db.Entry(edad).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();

                this.Close();
            }
        }