Пример #1
0
        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();
            }
            FermentableIngredientDataModel 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;
        }
Пример #2
0
 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();
     }
 }