public async Task Delete(UserWordMapping entity) { using (var db = new PostgresDBProvider()) using (var cmd = new NpgsqlCommand("DELETE FROM user_word_mapping WHERE id='@id';", db.Connection)) { cmd.Parameters.AddWithValue("@id", entity.Id); using (var reader = cmd.ExecuteReader()) { await cmd.ExecuteNonQueryAsync(); } } }
public async Task <UserWordMapping> Upsert(UserWordMapping entity) { var word = await GetById(entity.Id); using (var db = new PostgresDBProvider()) { if (word == null) { return(await Insert(entity)); } else { return(await Update(entity)); } } }
public async Task <UserWordMapping> Insert(UserWordMapping entity) { using (var db = new PostgresDBProvider()) using (var cmd = new NpgsqlCommand("INSERT INTO user_word_mapping (user_id, word_id, value) VALUES (@user_id, @word_id, @value);", db.Connection)) { cmd.Parameters.AddWithValue("user_id", entity.UserId); cmd.Parameters.AddWithValue("word_id", entity.WordId); cmd.Parameters.AddWithValue("value", entity.Value); using (var reader = cmd.ExecuteReader()) { await cmd.ExecuteNonQueryAsync(); return(await GetByWordId(entity.WordId)); } } }
public async Task <UserWordMapping> Update(UserWordMapping entity) { using (var db = new PostgresDBProvider()) using (var cmd = new NpgsqlCommand("UPDATE user_word_mapping SET value=@value, user_id=@userId, word_id=@wordId WHERE id=@id;", db.Connection)) { cmd.Parameters.AddWithValue("id", entity.Id); cmd.Parameters.AddWithValue("userId", entity.UserId); cmd.Parameters.AddWithValue("wordId", entity.WordId); cmd.Parameters.AddWithValue("value", entity.Value); using (var reader = cmd.ExecuteReader()) { await cmd.ExecuteNonQueryAsync(); return(entity); } } }