Ejemplo n.º 1
0
        public ActionResult Delete(int Id) // Recibe el modelo
        {
            using (var db = new CursomvcEntities())
            {
                var oUser = db.user.Find(Id);
                oUser.idState = 3;                                               // Estado 3 para eliminado

                db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; // Se le indica a EF que el objego oUser se editó
                db.SaveChanges();
            }

            return(Content("1")); // Content se usa para en vez de regresar una vista, regresar un contenido
        }
Ejemplo n.º 2
0
        public ActionResult Edit(EditUserViewModel model) // Recibe el modelo
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new CursomvcEntities())
            {
                var oUser = db.user.Find(model.Id);
                oUser.email = model.Email;
                oUser.edad  = model.Edad;

                if (model.Password != null && model.Password.Trim() != "")
                {
                    oUser.password = model.Password;
                }

                db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; // Se le indica a EF que el objego oUser se editó
                db.SaveChanges();
            }

            return(Redirect(Url.Content("~/User/")));
        }