public ActionResult Edit(string id, EditUserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.FirstOrDefault(x => x.Id == id);

                if (user == null)
                {
                    return(HttpNotFound());
                }

                if (!string.IsNullOrEmpty(viewModel.Password))
                {
                    var hasher       = new PasswordHasher();
                    var passwordHash = hasher.HashPassword(viewModel.Password);
                    user.PasswordHash = passwordHash;
                }

                user.Email    = viewModel.User.Email;
                user.UserName = viewModel.User.Email;
                this.SetUserRoles(viewModel, user, db);

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("List"));
            }
            return(View(viewModel));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "ClientId,Name")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }