protected async Task <IActionResult> AddNewUser(AdminUserInfo adminUserInfo) { // ensure there is a ADMINISTRATION_ROLE // Ensure a user named [email protected] is an Administrator var user = await _userManager.FindByEmailAsync(adminUserInfo.Email); IdentityResult results; if (user == null) { user = new ApplicationUser(); user.UserName = adminUserInfo.UserName; user.Email = adminUserInfo.Email; results = await _userManager.CreateAsync(user, adminUserInfo.Password); if (results.Succeeded) { await UpdateUserRole(user, adminUserInfo.Roles); UpdateUserIdCommand updateUserIdCommand = new UpdateUserIdCommand(adminUserInfo.PilotId, user.Id.ToString()); int result = await _mediator.Send(updateUserIdCommand); //await _memberService.UpdatePilotUserId(adminUserInfo.PilotId, user.Id.ToString()); } } else { } return(Ok()); }
public async Task <IActionResult> EditUser(AdminUserInfo adminUserInfo) { var user = await _userManager.FindByIdAsync(adminUserInfo.Id); if (user != null) { if (!string.IsNullOrEmpty(adminUserInfo.Password)) { user.PasswordHash = _passwordHasher.HashPassword(user, adminUserInfo.Password); } if (!string.IsNullOrEmpty(adminUserInfo.Email)) { user.Email = adminUserInfo.Email; } if (!string.IsNullOrEmpty(adminUserInfo.Email)) { IdentityResult identityResult = await _userManager.UpdateAsync(user); if (!identityResult.Succeeded) { var error = identityResult.Errors.FirstOrDefault().Description; return(StatusCode(10000)); } await UpdateUserRole(user, adminUserInfo.Roles); UpdateUserIdCommand updateUserIdCommand = new UpdateUserIdCommand(adminUserInfo.PilotId, user.Id.ToString()); int result = await _mediator.Send(updateUserIdCommand); //await _memberService.UpdatePilotUserId(adminUserInfo.PilotId, user.Id.ToString()); return(result >= 0 ? Ok(): StatusCode(10003)); } return(StatusCode(10002)); } return(StatusCode(10001)); }