public ActionResult UpdateAdminAccount(UpdateAdminAccountViewModel model) { if (ModelState.IsValid) { HashAlgorithm algorithm = MD5.Create(); algorithm.ComputeHash(Encoding.UTF8.GetBytes(model.Password)); string id = CurrentUser.Get.UserId; ApplicationUser user = UserManager.FindById(id); user.Name = model.Name; user.LastName = model.LastName; user.Email = model.Email; user.NumberIdentification = model.NumberIdentification; user.EmailConfirmed = true; // user.PasswordHash=algorithm.ToString() var result = UserManager.Update(user); if (result.Succeeded) { var data = UserManager.FindById(id); var juser = JsonConvert.SerializeObject(new CurrentUser { Email = data.Email, Name = data.Name, LastName = data.LastName, UserName = data.UserName, UserId = data.Id, NumberIdentification = data.NumberIdentification }); //UserManager.RemoveClaim(id, new Claim(ClaimTypes.UserData, juser)); //UserManager.AddClaim(id, new Claim(ClaimTypes.UserData, juser)); return(RedirectToAction("Login", "Account")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult UpdateAdminAccount(UpdateAdminAccountViewModel model) { HashAlgorithm algorithm = MD5.Create(); ApplicationDbContext dbContext = new ApplicationDbContext(); var query = dbContext.Users.FirstOrDefault(); string id = query.Id; ApplicationUser user = UserManager.FindById(id); user.Name = model.Name; user.LastName = model.LastName; user.Email = model.Email; user.NumberIdentification = model.NumberIdentification; user.EmailConfirmed = true; var result = UserManager.Update(user); if (result.Succeeded) { var data = UserManager.FindById(id); var juser = JsonConvert.SerializeObject(new CurrentUser { Email = data.Email, Name = data.Name, LastName = data.LastName, UserName = data.UserName, UserId = data.Id, NumberIdentification = data.NumberIdentification }); UserManager.AddClaim(id, new Claim(ClaimTypes.UserData, juser)); return(RedirectToAction("Login", "Account")); } AddErrors(result); // If we got this far, something failed, redisplay form return(View(model)); }