Пример #1
0
        public ActionResult Agregar2(string nombre, string apellido, string parentesco, string telefono)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            try
            {
                Representante rep = new Representante();
                rep.Nombres    = nombre;
                rep.Apellidos  = apellido;
                rep.Parentesco = parentesco;
                rep.Telefono   = Int32.Parse(telefono);

                using (var db = new RepresentanteContext())
                {
                    db.Representante.Add(rep);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Error al agregar Representante");
                return(View());
            }
        }
Пример #2
0
        public ActionResult Editar(Representante rep)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            try
            {
                using (var db = new RepresentanteContext())
                {
                    Representante representante = db.Representante.Find(rep.Cedula);

                    representante.Nombres    = rep.Nombres;
                    representante.Apellidos  = rep.Apellidos;
                    representante.Parentesco = rep.Parentesco;
                    representante.Telefono   = rep.Telefono;

                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        public ActionResult Eliminar(int cedula)
        {
            using (var db = new RepresentanteContext())
            {
                Representante rep = db.Representante.Find(cedula);
                db.Representante.Remove(rep);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Пример #4
0
 public ActionResult Editar(int cedula)
 {
     try
     {
         using (var db = new RepresentanteContext())
         {
             Representante rep = db.Representante.Find(cedula);
             return(View(rep));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #5
0
 public ActionResult Agregar(Representante representante)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     try
     {
         using (var db = new RepresentanteContext())
         {
             db.Representante.Add(representante);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "Error al agregar Representante");
         return(View());
     }
 }
Пример #6
0
 public ActionResult Buscar(string searchby, string search)
 {
     try
     {
         using (var db = new RepresentanteContext())
         {
             if (searchby == "Apellido")
             {
                 return(View(db.Representante.Where(x => x.Apellidos == search || search == null).ToList()));
             }
             else
             {
                 return(View(db.Representante.Where(x => x.Nombres.StartsWith(search) || search == null).ToList()));
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }