Exemple #1
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 #2
0
        public static void DeleteRecipe(RecipeDataModel recipe)
        {
            using var connection = DatabaseUtility.GetNewConnection();
            if (recipe.YeastIngredient != null)
            {
                YeastUtility.DeleteYeastIngredient(((YeastIngredientDataModel)recipe.YeastIngredient).YeastIngredientId, connection);
            }

            foreach (FermentableIngredientDataModel fermentableIngredient in recipe.FermentableIngredients)
            {
                FermentableUtility.DeleteFermentableIngredient(fermentableIngredient.FermentableId, connection);
            }

            foreach (HopsIngredientDataModel hopsIngredient in recipe.HopsIngredients)
            {
                HopsUtility.DeleteHopsIngredient(hopsIngredient.HopsId, connection);
            }

            using var deleteRecipeCommand   = connection.CreateCommand();
            deleteRecipeCommand.CommandText = "DELETE FROM Recipes WHERE id = @id";
            deleteRecipeCommand.Parameters.AddWithValue("id", recipe.RecipeId);
            deleteRecipeCommand.ExecuteNonQuery();
        }
Exemple #3
0
        public static IEnumerable <RecipeDataModel> GetSavedRecipes(IList <Style> availableBeerStyles)
        {
            using SQLiteConnection connection     = DatabaseUtility.GetNewConnection();
            using SQLiteCommand getRecipesCommand = connection.CreateCommand();
            getRecipesCommand.CommandText         = "SELECT Recipes.id, Recipes.size, Recipes.boilTime, Recipes.name, Styles.name FROM Recipes " +
                                                    "LEFT JOIN Styles ON Styles.id = Recipes.beerStyleInfo";
            using SQLiteDataReader reader = getRecipesCommand.ExecuteReader();
            while (reader.Read())
            {
                string styleName   = reader[4].ToString();
                Style  recipeStyle = availableBeerStyles.FirstOrDefault(style => style.Name == styleName);
                int    recipeId    = reader.GetInt32(0);
                var    recipe      = new RecipeDataModel(recipeId)
                {
                    Size            = reader.GetFloat(1),
                    BoilTime        = reader.GetInt32(2),
                    Name            = reader.GetString(3),
                    Style           = recipeStyle,
                    YeastIngredient = YeastUtility.GetYeastIngredientForRecipe(recipeId, connection)
                };

                foreach (var hopsIngredient in HopsUtility.GetHopsIngredientsForRecipe(recipeId, connection))
                {
                    hopsIngredient.PropertyChanged += recipe.Ingredient_PropertyChanged;
                    recipe.HopsIngredients.Add(hopsIngredient);
                }

                foreach (var fermentableIngredient in FermentableUtility.GetFermentableIngredientsForRecipe(recipeId, connection))
                {
                    fermentableIngredient.PropertyChanged += recipe.Ingredient_PropertyChanged;
                    recipe.FermentableIngredients.Add(fermentableIngredient);
                }

                yield return(recipe);
            }
            connection.Close();
        }
Exemple #4
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 #5
0
 public static void DeleteHopsIngredient(int hopsIngredientId)
 {
     using SQLiteConnection connection = DatabaseUtility.GetNewConnection();
     DeleteHopsIngredient(hopsIngredientId, connection);
     connection.Close();
 }
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);
        }
Exemple #7
0
 public static void DeleteFermentableIngredient(int fermentableIngredientId)
 {
     using SQLiteConnection connection = DatabaseUtility.GetNewConnection();
     DeleteFermentableIngredient(fermentableIngredientId, connection);
     connection.Close();
 }
Exemple #8
0
 public static void DeleteGravityReading(int gravityReadingId)
 {
     using SQLiteConnection connection = DatabaseUtility.GetNewConnection();
     DeleteGravityReading(gravityReadingId, connection);
     connection.Close();
 }