Example #1
0
        public ActionResult NuevoRegistro(TablaViewsModels Model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (ConectionsDataBase dataBase = new ConectionsDataBase())
                    {
                        var persona = new Peoples();
                        persona.Nombre   = Model.Nombre;
                        persona.Apellido = Model.Apellido;
                        persona.Edad     = Model.Edad;
                        persona.Sexo     = Model.Sexo;
                        persona.Correo   = Model.Correo;

                        dataBase.Peoples.Add(persona);
                        dataBase.SaveChanges();
                    }
                    return(Redirect("/"));
                }
                return(View(Model));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #2
0
        public ActionResult ActualizarPersona(TablaViewsModels Model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (ConectionsDataBase dataBase = new ConectionsDataBase())
                    {
                        var tabla = dataBase.Peoples.Find(Model.Id_person);
                        tabla.Nombre   = Model.Nombre;
                        tabla.Apellido = Model.Apellido;
                        tabla.Edad     = Model.Edad;
                        tabla.Sexo     = Model.Sexo;
                        tabla.Correo   = Model.Correo;

                        dataBase.Entry(tabla).State = EntityState.Modified;
                        dataBase.SaveChanges();
                    }
                    return(Redirect("/"));
                }
                return(View(Model));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #3
0
 public ActionResult BorrarPersona(int Id)
 {
     using (ConectionsDataBase dataBase = new ConectionsDataBase())
     {
         var tabla = dataBase.Peoples.Find(Id);
         dataBase.Peoples.Remove(tabla);
         dataBase.SaveChanges();
     }
     return(Redirect("/"));
 }