private void AddFermentableIngredient(Fermentable fermentable) { FermentableIngredientDataModel fermentableIngredient = FermentableUtility.CreateFermentableIngredient(fermentable, CurrentRecipe.RecipeId); fermentableIngredient.PropertyChanged += CurrentRecipe.Ingredient_PropertyChanged; CurrentRecipe.FermentableIngredients.Add(fermentableIngredient); }
internal static void UpdateFermentableIngredient(FermentableIngredientDataModel fermentableIngredient, SQLiteConnection connection) { using SQLiteCommand updateCommand = connection.CreateCommand(); updateCommand.CommandText = "UPDATE FermentableIngredients SET amount = @amount WHERE id = @id"; updateCommand.Parameters.AddWithValue("id", fermentableIngredient.FermentableId); updateCommand.Parameters.AddWithValue("amount", fermentableIngredient.Amount); updateCommand.ExecuteNonQuery(); }
internal static FermentableIngredientDataModel CreateFermentableIngredient(Fermentable fermentableInfo, int recipeId, SQLiteConnection connection) { using SQLiteCommand insertIngredientCommand = connection.CreateCommand(); insertIngredientCommand.CommandText = "INSERT INTO FermentableIngredients (amount, fermentableInfo) VALUES(0, (SELECT id FROM Fermentables WHERE name = @name))"; insertIngredientCommand.Parameters.AddWithValue("name", fermentableInfo.Name); insertIngredientCommand.ExecuteNonQuery(); var fermentableIngredient = new FermentableIngredientDataModel(fermentableInfo, DatabaseUtility.GetLastInsertedRowId(connection)); using SQLiteCommand insertJunctionCommand = connection.CreateCommand(); insertJunctionCommand.CommandText = "INSERT INTO FermentablesInRecipe (fermentableIngredient, recipe) VALUES(@fermentableIngredientId, @recipeId)"; insertJunctionCommand.Parameters.AddWithValue("fermentableIngredientId", fermentableIngredient.FermentableId); insertJunctionCommand.Parameters.AddWithValue("recipeId", recipeId); insertJunctionCommand.ExecuteNonQuery(); return(fermentableIngredient); }