public async Task <bool> CheckIfEmailExists(string email) { bool userExists = false; try { using (SqlConnection con = new SqlConnection(this.ConnectionString)) { SqlCommand cmd = new SqlCommand(UserQueries.CountUserByEmail(), con); cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value = email; await con.OpenAsync(); SqlDataReader reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { int numberOfUsers; GetNumberOfUsers(out numberOfUsers, reader); if (numberOfUsers > 0) { userExists = true; } } } } catch (Exception ex) { this.logger.LogError(ex.Message); throw ex; } return(userExists); }