public ActionResult Editar(Alumno a) { if (!ModelState.IsValid) { return(View()); } try { using (var db = new AlumnoContexto()) { var al = db.Alumno.Find(a.id); al.Nombres = a.Nombres; al.Apellidos = a.Apellidos; al.Edad = a.Edad; al.Sexo = a.Sexo; db.SaveChanges(); return(RedirectToAction("IndexdeAlumno")); } } catch (Exception) { throw; } }
public ActionResult EliminarUsuario(int id) { using (var db = new AlumnoContexto()) { Alumno al = db.Alumno.Find(id); db.Alumno.Remove(al); db.SaveChanges(); return(RedirectToAction("IndexdeAlumno")); } }
[ValidateAntiForgeryToken] //this is for validate the if the format is correct public ActionResult Agregar(Alumno a) { if (!ModelState.IsValid) { return(View()); } try { using (var db = new AlumnoContexto()) { a.Fecha_Registro = DateTime.Now; db.Alumno.Add(a); db.SaveChanges(); return(RedirectToAction("IndexdeAlumno")); } } catch (Exception e) { ModelState.AddModelError("", "Error al Crear Alumno" + e.Message); return(View()); } }