public async Task<IdentityResult> CreateAsync(ApplicationUser user)
 {
     return await _userManager.CreateAsync(user);
 }
 public async Task<IdentityResult> RegisterUserAsync(UserModel userModel)
 {
     var user = new ApplicationUser(userModel.Username);
     return await _userManager.CreateAsync(user, userModel.Password);
 }
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var verifiedAccessToken = await VerifyExternalAccessTokenAsync(model.Provider, model.ExternalAccessToken);
            if (verifiedAccessToken == null)
            {
                return BadRequest("Invalid provider or external access token");
            }

            var user = await _userRepository.FindUserAsync(new UserLoginInfo(model.Provider, verifiedAccessToken.UserId));
            if (user != null)
            {
                return BadRequest("External user is already registered");
            }

            user = new ApplicationUser(model.Username);
            var result = await _userRepository.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            var externalLoginInfo = new ExternalLoginInfo
            {
                DefaultUserName = model.Username,
                Login = new UserLoginInfo(model.Provider, verifiedAccessToken.UserId)
            };

            result = await _userRepository.AddLoginAsync(user.Id, externalLoginInfo.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok(GetLocalAccessTokenResponse(model.Username));
        }