public async Task UpdateAsync(int id, UserInDbModel info) => await ExecuteSqlCommand( "UPDATE Users SET Login = @login, Salt = @Salt, HashedPassword = @password, Nickname = @nickname, Role = @role WHERE Id = @id;", async command => await command.ExecuteNonQueryAsync(), new SqlParameter[] { new SqlParameter("@id", id), new SqlParameter("@Login", info.Login), new SqlParameter("@Nickname", info.Nickname), new SqlParameter("@Role", info.Role), new SqlParameter("@Salt", info.Salt), new SqlParameter("@password", info.HashedPassword), });
private async Task <UserInDbModel> ReturnUser(SqlCommand command) { SqlDataReader reader = await command.ExecuteReaderAsync(); UserInDbModel user = reader.Read() ? new UserInDbModel( (int)reader["Id"], (string)reader["Login"], (string)reader["Nickname"], (int)reader["Role"], (string)reader["Salt"], (string)reader["HashedPassword"]) : null; reader.Close(); return(user); }
public async Task <int> CreateAsync(UserInDbModel info) => await ExecuteSqlCommand( "INSERT INTO Users (Login, Nickname, Role, Salt, HashedPassword) VALUES (@Login, @Nickname, @Role, @Salt, @Password); SELECT SCOPE_IDENTITY();", async command => Convert.ToInt32(await command.ExecuteScalarAsync()), new SqlParameter[] { new SqlParameter("@Login", info.Login), new SqlParameter("@Nickname", info.Nickname), new SqlParameter("@Role", info.Role), new SqlParameter("@Salt", info.Salt), new SqlParameter("@password", info.HashedPassword), new SqlParameter { ParameterName = "@id", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output } });