public void updateAllTables(Ingredient i, Recipe r)
        {
            var dbRecipes     = new DatabaseAccessRecipe();
            var dbIngredients = new DatabaseAccessIngredient();
            var dbConsumptionOuncesConsumed = new DatabaseAccessConsumptionOuncesConsumed();
            var dbConsumption        = new DatabaseAccessConsumption();
            var dbDensities          = new DatabaseAccessDensities();
            var dbDensityInformation = new DatabaseAccessDensityInformation();
            var dbCosts     = new DatabaseAccessCosts();
            var myCostTable = dbCosts.queryCostTable();

            foreach (var ingredient in myCostTable)
            {
                if (ingredient.ingredientId == i.ingredientId)
                {
                    if (ingredient.sellingPrice == 0m && i.sellingPrice != 0m)
                    {
                        dbCosts.updateCostDataTable(i);
                        break;
                    }
                }
            }
            dbRecipes.UpdateRecipe(r);
            dbIngredients.UpdateIngredient(i);
            var updatedIngredient = queryAllRelevantTablesSQLByIngredientName(i);

            dbDensityInformation.updateDensityInfoTable(i);
            dbDensities.updateDensityTable(i);
            dbCosts.updateCostDataTable(i);
        }
Exemple #2
0
        //i need to rewrite the query to call a different () to get all the information for all the ingredients... i'm not getting an ing.id, densities...
        //only the name and the measurement

        public void UpdateRecipeYield(Recipe r)
        {
            var db          = new DatabaseAccess();
            var dbDensities = new DatabaseAccessDensityInformation();
            var convert     = new ConvertMeasurement();
            var myRecipeBox = MyRecipeBox();

            foreach (var recipe in myRecipeBox)
            {
                var myIngredients  = db.queryAllTablesForAllIngredients(recipe.ingredients);
                var tempIngredient = new Ingredient();
                if (recipe.id == r.id)
                {
                    foreach (var ingredient in recipe.ingredients)
                    {
                        tempIngredient = ingredient;
                        if (tempIngredient.density == 0)
                        {
                            tempIngredient.density = dbDensities.queryDensityTableRowDensityValueByName(ingredient);
                        }
                        tempIngredient.measurement    = convert.AdjustIngredientMeasurement(ingredient.measurement, recipe.yield, r.yield);
                        tempIngredient.ouncesConsumed = ingredient.ouncesConsumed * (HomeController.currentRecipe.yield / r.yield);
                        db.updateAllTables(tempIngredient, r);
                        var myUpdatedIngredient = db.queryAllRelevantTablesSQLByIngredientName(tempIngredient);
                    }
                    recipe.yield = r.yield;
                    GetFullRecipePrice(recipe);
                    var myUpdatedIngredients = db.queryAllTablesForAllIngredients(recipe.ingredients);
                }
            }
        }
        public void insertIngredientIntoAllTables(Ingredient i, Recipe r)
        {
            var dbRecipes     = new DatabaseAccessRecipe();
            var dbIngredients = new DatabaseAccessIngredient();
            var dbConsumptionOuncesConsumed = new DatabaseAccessConsumptionOuncesConsumed();
            var dbConsumption          = new DatabaseAccessConsumption();
            var dbDensities            = new DatabaseAccessDensities();
            var dbDensitiesInformation = new DatabaseAccessDensityInformation();
            var dbCosts   = new DatabaseAccessCosts();
            var myRecipes = dbRecipes.queryRecipes();
            //var myIngredientBox = dbIngredients.queryAllIngredientsFromIngredientTable();
            var myIngredients = queryAllRelevantTablesSQLByIngredientName(i);
            var myRecipe      = dbRecipes.queryRecipeFromRecipesTableByName(r);

            if (string.IsNullOrEmpty(myRecipe.name))
            {
                dbRecipes.InsertRecipe(r);
            }
            dbIngredients.insertIngredient(i, r);
            var myIng = queryAllRelevantTablesSQLByIngredientName(i);

            dbDensitiesInformation.insertIngredientIntoDensityInfoDatabase(i);
            dbDensities.insertIngredientDensityData(i);
            dbConsumption.insertIngredientConsumtionData(i);
            var myIngUpdated = queryAllRelevantTablesSQLByIngredientName(i);

            dbCosts.insertIngredientCostDataCostTable(i);
            var myConsumptionIngredient = dbConsumption.queryConsumptionTableRowByName(i);

            dbIngredients.UpdateIngredient(i);
            var myUpdatedIngredient = queryAllRelevantTablesSQLByIngredientName(i);
        }
        public void insertIngredientDensityData(Ingredient i)
        {
            var convert = new ConvertWeight();
            var db      = new DatabaseAccess();
            var dbDensityInformation = new DatabaseAccessDensityInformation();

            if (i.sellingPrice == 0m)
            {
                myItemResponse = returnItemResponse(i);
            }
            i.density = dbDensityInformation.queryDensityTableRowDensityValueByName(i);
            if (i.sellingPrice == 0m)
            {
                i.sellingPrice = myItemResponse.salePrice;
            }
            if (i.classification.ToLower() == "egg" || i.classification.ToLower() == "eggs")
            {
                i.sellingWeightInOunces = convert.NumberOfEggsFromSellingQuantity(i.sellingWeight);
            }
            else
            {
                i.sellingWeightInOunces = convert.ConvertWeightToOunces(i.sellingWeight);
            }
            if (i.sellingWeightInOunces == 0m)
            {
                throw new Exception("Selling Weight In Ounces is 0; please check that your Selling Weight is an appopriate weight.");
            }
            i.pricePerOunce = Math.Round((i.sellingPrice / i.sellingWeightInOunces), 4);
            if (string.IsNullOrEmpty(i.classification))
            {
                i.classification = " ";
            }
            var commandText = @"Insert into densities (name, density, selling_weight, selling_weight_ounces, selling_price, price_per_ounce) 
                            values (@name, @density, @selling_weight, @selling_weight_ounces, @selling_price, @price_per_ounce);";

            db.executeVoidQuery(commandText, cmd => {
                cmd.Parameters.AddWithValue("@name", i.name);
                cmd.Parameters.AddWithValue("@density", i.density);
                cmd.Parameters.AddWithValue("@selling_weight", i.sellingWeight);
                cmd.Parameters.AddWithValue("@selling_price", i.sellingPrice);
                cmd.Parameters.AddWithValue("@selling_weight_ounces", i.sellingWeightInOunces);
                cmd.Parameters.AddWithValue("@price_per_ounce", i.pricePerOunce);
                return(cmd);
            });
        }