Ejemplo n.º 1
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 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);
            });
        }