public async Task <IActionResult> Details(string id) { if (id == null) { return(NotFound()); } var user = await GetUserById(id); if (user == null) { return(NotFound()); } var vm = new UserManagementDetailsViewModel { UserId = id, UserName = user.UserName, Email = user.Email, Password = "******", Reports = NumberOfReports(user) }; return(View(vm)); }
public IActionResult UserDelete(string username) { var asset = _manage.GetRegisteredUserbyUsername(username); var model = new UserManagementDetailsViewModel { Email = asset.Email, EmailConfirmed = asset.EmailConfirmed, Username = asset.UserName, Address = asset.Address, Country = asset.Country, FirstName = asset.FirstName, LastName = asset.LastName, PhoneNumber = asset.PhoneNumber, ZipCode = asset.ZipCode }; return(View(model)); }
public async Task <IActionResult> UserEdit(UserManagementDetailsViewModel vm) { if (!ModelState.IsValid) { return(View(vm)); } var user = await _userManager.FindByNameAsync(vm.Username); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var email = user.Email; if (vm.Email != email) { var setEmailResult = await _userManager.SetEmailAsync(user, vm.Email); if (!setEmailResult.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting email for user with ID '{user.Id}'."); } } var phoneNumber = user.PhoneNumber; if (vm.PhoneNumber != phoneNumber) { var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, vm.PhoneNumber); if (!setPhoneResult.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } var firstName = user.FirstName; if (vm.FirstName != firstName) { user.FirstName = vm.FirstName; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } var lastName = user.LastName; if (vm.LastName != lastName) { user.LastName = vm.LastName; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } var country = user.Country; if (vm.Country != country) { user.Country = vm.Country; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } var address = user.Address; if (vm.Address != address) { user.Address = vm.Address; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } var zipcode = user.ZipCode; if (vm.ZipCode != zipcode) { user.ZipCode = vm.ZipCode; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { throw new ApplicationException( $"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); } } StatusMessage = "Your profile has been updated"; return(RedirectToAction("UserDetails", new { username = user.UserName })); }