コード例 #1
0
        public ActionResult EditUser(EditUserViewModel model)
        {
            var usr      = new UserManager <Users>(new UserStore <Users>(context));
            var findUser = usr.FindById(model.User.Id);

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("Password", "Passwords do not match!");
                model.SetRoleItems();
                return(View(model));
            }
            else
            {
                usr.ChangePassword(model.User.Id, model.Password, model.ConfirmPassword);
            }

            if (ModelState.IsValid)
            {
                var userbyId = usr.FindById(findUser.Id);
                var userRole = usr.GetRoles(findUser.Id);

                usr.RemoveFromRoles(userbyId.Id, userRole.ToArray());

                usr.AddToRole(userbyId.Id, model.Role);

                userbyId.FirstName = model.User.FirstName;
                userbyId.LastName  = model.User.LastName;
                userbyId.Email     = model.User.Email;


                usr.Update(userbyId);
            }

            return(RedirectToAction("Users"));
        }
コード例 #2
0
        public ActionResult EditUser(string id)
        {
            var model = new EditUserViewModel();

            model.SetRoleItems();
            model.User = ctxs.GetUserById(id);
            return(View(model));
        }