Exemplo n.º 1
0
        public async Task<ActionResult> EditUser(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = UserManager.FindById(model.UserId);

                user.UserName = model.UserName;
                user.FirstName = model.FirstName;
                user.MiddleName = model.MiddleName;
                user.LastName = model.LastName;
                user.Email = model.Email;
                user.IsActive = model.IsActive;

                IdentityResult result = await UserManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    if (model.NewPassword != null)
                    {
                        UserManager.RemovePassword(user.Id);
                        UserManager.AddPassword(user.Id, model.NewPassword);
                    }
                    return RedirectToAction("Users", "User");
                }
                AddErrors(result);
            }
            return View(model);
        }
Exemplo n.º 2
0
        // GET: /User/Edit 
        public ActionResult EditUser(string userName, AccountController.ManageMessageId? message = null)
        {
            using (var db = new ApplicationDbContext())
            {
                ApplicationUser user = db.Users.First(u => u.UserName == userName);
                var model = new EditUserViewModel();

                model.UserId = user.Id;
                model.UserName = user.UserName;
                model.FirstName = user.FirstName;
                model.MiddleName = user.MiddleName;
                model.LastName = user.LastName;
                model.Email = user.Email;
                model.IsActive = user.IsActive;

                ViewBag.MessageId = message;

                return View(model);
            }
        }