public async Task <int> CreateAsync(FridgeItem fridgeItem) { Console.WriteLine("[Repo] item: " + fridgeItem.ArticleName); Console.WriteLine("[Repo] item: " + fridgeItem.Weight); Console.WriteLine("[Repo] item: " + fridgeItem.Quantity); int createdId = 0; if (_environment.IsDevelopment()) { Console.WriteLine("(CreateAsync) in DBFridgeRepository "); } using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = connection; cmd.CommandType = CommandType.Text; cmd.CommandText = _insertQuery; cmd.Parameters.AddWithValue("@param1", fridgeItem.ArticleName); cmd.Parameters.AddWithValue("@param2", fridgeItem.Quantity); cmd.Parameters.AddWithValue("@param3", fridgeItem.Weight); try { connection.Open(); createdId = Convert.ToInt32(await cmd.ExecuteScalarAsync()); Console.WriteLine("CreatedID: " + createdId); } catch (Exception e) { Console.WriteLine(e.Message.ToString(), "Error Message"); } if (connection.State == ConnectionState.Open) { connection.Close(); } } return(createdId); }
public async Task <bool> UpdateAsync(FridgeItem item) { int rowsAffected = 0; if (_environment.IsDevelopment()) { Console.WriteLine("(UpdateAsync) in DBFridgeRepository "); } using (SqlConnection connection = new SqlConnection(_connectionString)) using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = connection; cmd.CommandType = CommandType.Text; cmd.CommandText = _updateQuery; cmd.Parameters.AddWithValue("@param1", item.ArticleName); cmd.Parameters.AddWithValue("@param2", item.Quantity); cmd.Parameters.AddWithValue("@param3", item.Weight); cmd.Parameters.AddWithValue("@id", item.ID); try { connection.Open(); rowsAffected = await cmd.ExecuteNonQueryAsync(); } catch (Exception e) { Console.WriteLine(e.Message.ToString(), "Error Message"); } if (connection.State == ConnectionState.Open) { connection.Close(); } } return(rowsAffected != 0); }
public Task <bool> UpdateAsync(FridgeItem item) { throw new NotImplementedException(); }
public Task <int> CreateAsync(FridgeItem fridgeItem) { throw new NotImplementedException(); }