public async Task <AuthResponse> SignUp(SignUpModel signUpModel, ModelStateDictionary modelState)
        {
            var response     = default(AuthResponse);
            var errorMessage = "Sign up error";

            if (!modelState.IsValid)
            {
                response = AuthResponseError.FromModelStateErrors(modelState, errorMessage);
            }
            else
            {
                var user = await userManager.FindByEmailAsync(signUpModel.UserName);

                if (user != null)
                {
                    var errors = GetErrorsFromParams($"User {signUpModel.UserName} already exists");
                    response = AuthResponseError.GetBadRequestError(errors, errorMessage);
                }
                else
                {
                    response = await TryCreateUser(signUpModel, errorMessage);
                }
            }

            return(response);
        }
        public async Task <AuthResponse> SignIn(SignInModel signInModel, ModelStateDictionary modelState)
        {
            var response     = default(AuthResponse);
            var errorMessage = "Sign in error";

            if (!modelState.IsValid)
            {
                response = AuthResponseError.FromModelStateErrors(modelState, errorMessage);
            }
            else
            {
                var user = await userManager.FindByEmailAsync(signInModel.UserName);

                var errors = default(IEnumerable <string>);

                if (user == null)
                {
                    errors   = GetErrorsFromParams($"User {signInModel.UserName} was not found");
                    response = AuthResponseError.GetNotFoundError(errors, errorMessage);
                }
                else
                {
                    var result = await signInManager.PasswordSignInAsync(user, signInModel.Password, false, false);

                    if (!result.Succeeded)
                    {
                        errors   = GetErrorsFromParams($"Incorrect password");
                        response = AuthResponseError.GetBadRequestError(errors, errorMessage);
                    }
                    else
                    {
                        var token = await generateJwt.CreateToken(user);

                        var authModel = await AuthModel.FromAppUser(user, userManager, token);

                        response = new AuthResponseOk(authModel, "Sign in success");
                    }
                }
            }

            return(response);
        }