public ActionResult Eliminar(int Id) { using (IntentoEntities db = new IntentoEntities()) { var Persona = db.Persona.Find(Id); db.Persona.Remove(Persona); db.SaveChanges(); } return(Redirect("~/Persona/")); }
public ActionResult Nuevo(PersonaViewModels persona) { try { if (ModelState.IsValid) { using (IntentoEntities db = new IntentoEntities()) { var tabla = new Persona(); tabla.Nombre = persona.Nombre; tabla.Apellido = persona.Apellido; db.Persona.Add(tabla); db.SaveChanges(); } return(Redirect("~/Persona/")); } return(View(persona)); }catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Editar(PersonaViewModels persona) { try { if (ModelState.IsValid) { using (IntentoEntities db = new IntentoEntities()) { var tabla = db.Persona.Find(persona.Id); tabla.Nombre = persona.Nombre; tabla.Apellido = persona.Apellido; db.Entry(tabla).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(Redirect("~/Persona/")); } return(View(persona)); } catch (Exception ex) { throw new Exception(ex.Message); } }