2

The instance of entity type 'User' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked

public async Task<ApiResult<ChangePasswordDto>> ChangePassword(ChangePasswordDto change, CancellationToken cancellationToken)
{
    string currentUserName = User.Identity.Name;

    if (!ModelState.IsValid)
        return new ApiResult<ChangePasswordDto>(false, ApiResultStatusCode.BadRequest, change);
            
    User user = await userRepository.GetByUserNameAsync(cancellationToken, currentUserName);

    await userManager.ChangePasswordAsync(user, change.OldPassword, change.Password);

    return Ok();
}
Shanid
  • 557
  • 12
  • 30

0 Answers0