コード例 #1
0
 public ActionResult ListaCiudades()
 {
     using (var db = new AlumnoContexto())
     {
         return(PartialView(db.Ciudad.ToList()));
     }
 }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
 public static String NombreCiudad(int CodCiudad)
 {
     using (var db = new AlumnoContexto())
     {
         String nombre = db.Ciudad.Find(CodCiudad).Nombre;
         return(nombre);
     }
 }
コード例 #4
0
 public ActionResult DetallesUsuario(int id)
 {
     using (var db = new AlumnoContexto())
     {
         var al = db.Alumno.Find(id);
         return(View(al));
     }
 }
コード例 #5
0
 // GET: Ciudad
 public ActionResult Index()
 {
     using (var db = new AlumnoContexto())
     {
         var al = db.Ciudad.ToList();
         return(View(al));
     }
 }
コード例 #6
0
 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"));
     }
 }
コード例 #7
0
 // GET: Alumno
 public ActionResult IndexdeAlumno()
 {
     try
     {
         using (var db = new AlumnoContexto())
         {
             return(View(db.Alumno.ToList()));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #8
0
 public ActionResult Editar(int id)
 {
     try
     {
         using (var db = new AlumnoContexto())
         {
             //Alumno al = db.Alumno.Where(a => a.id == id).FirstOrDefault();//chosse the first which has that condicion and if not exist return a null, Where can be used in what ever case
             Alumno al2 = db.Alumno.Find(id);//this do the same but ONLY USE WHEN I KNOW THAT EXIST UNIQUE PRIMARY KEY
             return(View(al2));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #9
0
        [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());
            }
        }