public void RegisterUser(RegisterUserViewModel model) { UserExist(email: model.Email); if (model.Password != model.ConfirmPassword) { throw new ArgumentException("Passwords does not match!"); } var user = _mapper.RegisterToUserModel(model); IdentityResult identityResult = _userManager.CreateAsync(user, model.Password).Result; if (identityResult.Succeeded) { User currentUser = _userManager.FindByEmailAsync(user.Email).Result; _userManager.AddToRoleAsync(currentUser, "User"); } else { //TODO: Find way to add password errors to the view throw new ArgumentException(identityResult.Errors.ToString()); } LogInUser(new LoginUserViewModel { Email = model.Email, Password = model.Password }); //_userRepository.Insert(user); }