public async Task <IActionResult> Edit(int id, EditableUserViewModel <UserViewModel> editableViewModel) { var authorized = m_authorizationService.AuthorizationForUserEditAsync(User, RoleNames.Admin, id); if (!authorized.Result) { return(Forbid()); } var userViewModel = editableViewModel.UserViewModel; var twoFactorCheckResult = await m_twoFactorValidator.CheckTwoFactorIsValidOrNotEnabledAsync(id, userViewModel); if (!twoFactorCheckResult.IsSuccessful) { ModelState.AddModelError("", twoFactorCheckResult.Message); } var userModel = m_mapper.Map <UserModel>(userViewModel); var appUser = m_mapper.Map <ApplicationUser>(userModel); var result = m_identityUserManager.UpdateAsync(id, appUser).Result; if (result.Succeeded) { if (int.TryParse(User.FindFirst(JwtClaimTypes.Subject).Value, out var value) && value == id) { await m_signInManager.ReloginUserAsync(id, false); //HACK check for persistent login } return(RedirectToAction(nameof(View), new { id })); } ModelState.AddModelError(result.Errors.FirstOrDefault()?.Description); //TODO translate by code var viewModel = await ViewModelBuilder.BuildEditableUserViewModelAsync(ModelState, userViewModel); return(View(viewModel)); }
public async Task <IActionResult> Edit(int id) { var authorized = m_authorizationService.AuthorizationForUserEditAsync(User, RoleNames.Admin, id); if (!authorized.Result) { return(Forbid()); } var result = m_usersManager.GetUserById(id); if (result.HasError) { ModelState.AddModelError(result.Error.Message); return(View()); } var userViewmodel = m_mapper.Map <UserViewModel>(result.Result); var viewModel = await ViewModelBuilder.BuildEditableUserViewModelAsync(ModelState, userViewmodel); return(View(viewModel)); }