Ejemplo n.º 1
0
        internal static HopsIngredientDataModel CreateHopsIngredient(Hops hopsInfo, int recipeId, SQLiteConnection connection)
        {
            using (SQLiteCommand insertCommand = connection.CreateCommand())
            {
                insertCommand.CommandText = "INSERT INTO HopsIngredients (amount, time, type, form, use, hopsInfo) VALUES(0, 0, 'Bittering', 'Leaf', 'Boil', (SELECT id FROM Hops WHERE name = @name))";
                insertCommand.Parameters.AddWithValue("name", hopsInfo.Name);
                insertCommand.ExecuteNonQuery();
            }
            HopsIngredientDataModel hopsIngredient = new HopsIngredientDataModel(hopsInfo, DatabaseUtility.GetLastInsertedRowId(connection));

            using (SQLiteCommand insertJunctionCommand = connection.CreateCommand())
            {
                insertJunctionCommand.CommandText = "INSERT INTO HopsInRecipe (hopsIngredient, recipe) VALUES(@hopsIngredientId, @recipeId)";
                insertJunctionCommand.Parameters.AddWithValue("hopsIngredientId", hopsIngredient.HopsId);
                insertJunctionCommand.Parameters.AddWithValue("recipeId", recipeId);
                insertJunctionCommand.ExecuteNonQuery();
            }
            return hopsIngredient;
        }
Ejemplo n.º 2
0
 internal static void UpdateHopsIngredient(HopsIngredientDataModel hopsIngredient, SQLiteConnection connection)
 {
     using (SQLiteCommand updateCommand = connection.CreateCommand())
     {
         updateCommand.CommandText = "UPDATE HopsIngredients SET amount = @amount, time = @time, type = @type, form = @form, use = @use, dryHopTime = @dryHopTime WHERE id = @id";
         updateCommand.Parameters.AddWithValue("id", hopsIngredient.HopsId);
         updateCommand.Parameters.AddWithValue("amount", hopsIngredient.Amount);
         updateCommand.Parameters.AddWithValue("time", hopsIngredient.Time);
         updateCommand.Parameters.AddWithValue("type", hopsIngredient.FlavorType);
         updateCommand.Parameters.AddWithValue("form", hopsIngredient.Form);
         updateCommand.Parameters.AddWithValue("use", hopsIngredient.Use);
         updateCommand.Parameters.AddWithValue("dryHopTime", hopsIngredient.DryHopTime);
         updateCommand.ExecuteNonQuery();
     }
 }