Exemple #1
0
 internal static YeastIngredientDataModel CreateYeastIngredient(SQLiteConnection connection)
 {
     using var insertCommand   = connection.CreateCommand();
     insertCommand.CommandText = "INSERT INTO YeastIngredients (weight, volume, yeastInfo) VALUES(0, 0, 0)";
     insertCommand.ExecuteNonQuery();
     return(new YeastIngredientDataModel(null, DatabaseUtility.GetLastInsertedRowId(connection)));
 }
Exemple #2
0
        internal static GravityReadingDataModel CreateGravityReading(int batchId, SQLiteConnection connection)
        {
            DateTime date = DateTime.Now;

            using (SQLiteCommand insertGravityReadingCommand = connection.CreateCommand())
            {
                insertGravityReadingCommand.CommandText = "INSERT INTO GravityReadings (specificGravity, date) VALUES(0, @date)";
                insertGravityReadingCommand.Parameters.AddWithValue("date", date.ToString());
                insertGravityReadingCommand.ExecuteNonQuery();
            }
            GravityReadingDataModel gravityReading = new GravityReadingDataModel(DatabaseUtility.GetLastInsertedRowId(connection))
            {
                Date = date
            };

            using (SQLiteCommand insertJunctionCommand = connection.CreateCommand())
            {
                insertJunctionCommand.CommandText = "INSERT INTO GravityReadingsInBatch (gravityReading, batch) VALUES(@gravityReading, @batch)";
                insertJunctionCommand.Parameters.AddWithValue("gravityReading", gravityReading.GravityReadingId);
                insertJunctionCommand.Parameters.AddWithValue("batch", batchId);
                insertJunctionCommand.ExecuteNonQuery();
            }

            return(gravityReading);
        }
Exemple #3
0
        public static RecipeDataModel CreateRecipe()
        {
            using var connection = DatabaseUtility.GetNewConnection();
            var yeastIngredient = YeastUtility.CreateYeastIngredient(connection);

            using var insertCommand   = connection.CreateCommand();
            insertCommand.CommandText = "INSERT INTO Recipes (size, boilTime, name, beerStyleInfo, yeastIngredientInfo, mashProfileInfo) VALUES(0, 0, '', 0, @yeastIngredientInfo, 0)";
            insertCommand.Parameters.AddWithValue("yeastIngredientInfo", yeastIngredient.YeastIngredientId);
            insertCommand.ExecuteNonQuery();
            var recipe = new RecipeDataModel(DatabaseUtility.GetLastInsertedRowId(connection))
            {
                YeastIngredient = yeastIngredient
            };

            connection.Close();
            return(recipe);
        }
Exemple #4
0
        public static BatchDataModel CreateBatch(RecipeDataModel recipe)
        {
            BatchDataModel batch = null;

            using (SQLiteConnection connection = DatabaseUtility.GetNewConnection())
            {
                DateTime currentDate = DateTime.Now;
                using (SQLiteCommand insertCommand = connection.CreateCommand())
                {
                    insertCommand.CommandText = "INSERT INTO Batches (brewerName, assistantBrewerName, brewingDate, recipeInfo) VALUES ('', '', @brewingDate, @recipeInfo)";
                    insertCommand.Parameters.AddWithValue("brewingDate", currentDate.ToString());
                    insertCommand.Parameters.AddWithValue("recipeInfo", recipe.RecipeId);
                    insertCommand.ExecuteNonQuery();
                }
                batch = new BatchDataModel(DatabaseUtility.GetLastInsertedRowId(connection))
                {
                    BrewingDate = currentDate, Recipe = recipe
                };
                connection.Close();
            }
            return(batch);
        }
Exemple #5
0
        internal static HopsIngredientDataModel CreateHopsIngredient(Hops.Hops hopsInfo, int recipeId, SQLiteConnection connection)
        {
            using var 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 var 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);
        }
Exemple #6
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();
            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);
        }