public ActionResult assignCurrentIngredientNameForSearching(string ingredientName)
        {
            var rest = new MakeRESTCalls();

            currentIngredient = new Ingredient(rest.CapitalizeString(ingredientName));
            return(Redirect(string.Format("/home/recipe?name={0}", currentRecipe.name)));
        }
        public ActionResult Ingredient(string name, string measurement)
        {
            var rest = new MakeRESTCalls();

            if (string.IsNullOrEmpty(name))
            {
                return(Redirect("/home/RecipeBox"));
            }
            if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(measurement))
            {
                return(Redirect("/home/recipe?name=" + currentRecipe.name));
            }
            foreach (var ingredient in currentRecipe.ingredients)
            {
                if (ingredient.name == name && ingredient.measurement == measurement)
                {
                    currentIngredient = ingredient;
                }
            }
            ViewBag.currentrecipe                   = currentRecipe;
            ViewBag.currentingredient               = currentIngredient;
            ViewBag.currentitemresponselist         = rest.GetListItemResponses(currentIngredient);
            ViewBag.currentitemresponselistnoweight = rest.GetListItemResponseNoSellingWeights(currentIngredient);
            return(View());
        }
Пример #3
0
        public void TestMeasuredIngredientPriceIngredientsTablew()
        {
            var t       = new DatabaseAccess();
            var dbI     = new DatabaseAccessIngredient();
            var dbC     = new DatabaseAccessConsumption();
            var dbCosts = new DatabaseAccessCosts();
            var dbD     = new DatabaseAccessDensities();
            var rest    = new MakeRESTCalls();
            var r       = new Recipe("Wholesome Whole Wheat Bread")
            {
                id = 1
            };
            var i = new Ingredient("king arthur whole wheat flour")
            {
                recipeId      = 1,
                ingredientId  = 1,
                sellingWeight = "5 lb",
                measurement   = "1 1/2 cups",
                density       = 5.4m
            };

            t.initializeDatabase();
            dbI.insertIngredient(i, r);
            dbC.insertIngredientConsumtionData(i);
            dbD.insertIngredientDensityData(i);
            dbCosts.insertIngredientCostDataCostTable(i);
            var IngredientMeasuredPrice = dbI.MeasuredIngredientPrice(i);
            var myIngInfo = dbCosts.queryCostTable();

            Assert.AreEqual(.43m, IngredientMeasuredPrice);
        }
        public void TestSimilarities8()
        {
            var rest     = new MakeRESTCalls();
            var expected = true;
            var actual   = rest.SimilaritesInStrings("Softasilk Cake Flour", "cake flour");

            Assert.AreEqual(expected, actual);
        }
        public void TestSimilarities7()
        {
            var rest     = new MakeRESTCalls();
            var expected = false;
            var actual   = rest.SimilaritesInStrings("Granulated Sugar", "grnaulated sugar");

            Assert.AreEqual(expected, actual);
        }
        public void TestSimilarities5()
        {
            var rest     = new MakeRESTCalls();
            var expected = true;
            var actual   = rest.SimilaritesInStrings("All Purpose Flour", "all purpose flour");

            Assert.AreEqual(expected, actual);
        }
        public void TestCapitliazingWordsWithHyphens()
        {
            var rest     = new MakeRESTCalls();
            var expected = "All-Purpose Flour";
            var actual   = rest.CapitalizeString("All-purpose flour");

            Assert.AreEqual(expected, actual);
        }
        public void TestSimilarities2()
        {
            var rest     = new MakeRESTCalls();
            var expected = true;
            var actual   = rest.SimilaritesInStrings("confectioner's sugar", "confectioner's sugar");

            Assert.AreEqual(expected, actual);
        }
        public void TestCapitalizingWords3()
        {
            var rest     = new MakeRESTCalls();
            var expected = "I'm Just Trying To Make Something Longer To Make Sure I'm Not Going To Get Something Unexpected In My Code";
            var actual   = rest.CapitalizeString("I'm just trying to make something longer to make sure i'm not going to get something unexpected in my code");

            Assert.AreEqual(expected, actual);
        }
Пример #10
0
        public void TestSimilarities4()
        {
            var rest     = new MakeRESTCalls();
            var expected = false;
            var actual   = rest.SimilaritesInStrings("chocolate morsels", "chocolate chips");

            Assert.AreEqual(expected, actual);
        }
Пример #11
0
        public void TestCapitalizingWords2()
        {
            var rest     = new MakeRESTCalls();
            var expected = "All Purpose Unbleached Flour";
            var actual   = rest.CapitalizeString("all purpose unbleached flour");

            Assert.AreEqual(expected, actual);
        }
Пример #12
0
        public void TestCapitalizingWords()
        {
            var rest     = new MakeRESTCalls();
            var expected = "Vanilla";
            var actual   = rest.CapitalizeString("vanilla");

            Assert.AreEqual(expected, actual);
        }
Пример #13
0
        public void TestMeasuredIngredientPriceIngredientsTable2()
        {
            var t       = new DatabaseAccess();
            var dbI     = new DatabaseAccessIngredient();
            var dbC     = new DatabaseAccessConsumption();
            var dbCosts = new DatabaseAccessCosts();
            var dbD     = new DatabaseAccessDensities();
            var rest    = new MakeRESTCalls();
            var r       = new Recipe("Wholesome Whole Wheat Bread")
            {
                id = 1
            };
            var i = new Ingredient("King Arthur Whole Wheat Flour")
            {
                recipeId      = 1,
                ingredientId  = 1,
                sellingWeight = "5 lb",
                measurement   = "3 cups",
                density       = 5
            };
            var i2 = new Ingredient("Rumford Baking Powder")
            {
                recipeId      = 1,
                ingredientId  = 2,
                sellingWeight = "10 oz",
                measurement   = "1 teaspoon",
                density       = 8.4m
            };
            var i3 = new Ingredient("King Arthur All Purpose Flour")
            {
                recipeId      = 1,
                ingredientId  = 3,
                sellingWeight = "5 lb",
                measurement   = "2 cups",
                density       = 5
            };

            t.initializeDatabase();
            dbI.insertIngredient(i, r);
            dbI.insertIngredient(i2, r);
            dbI.insertIngredient(i3, r);
            dbC.insertIngredientConsumtionData(i);
            dbC.insertIngredientConsumtionData(i2);
            dbC.insertIngredientConsumtionData(i3);
            dbD.insertIngredientDensityData(i);
            dbD.insertIngredientDensityData(i2);
            dbD.insertIngredientDensityData(i3);
            dbCosts.insertIngredientCostDataCostTable(i);
            dbCosts.insertIngredientCostDataCostTable(i2);
            dbCosts.insertIngredientCostDataCostTable(i3);
            var ingredientMeasuredPrice1 = dbI.MeasuredIngredientPrice(i);
            var ingredient2MeasuredPrice = dbI.MeasuredIngredientPrice(i2);
            var ingredient3MeasuredPrice = dbI.MeasuredIngredientPrice(i3);

            Assert.AreEqual(.79m, ingredientMeasuredPrice1);
            Assert.AreEqual(.04m, ingredient2MeasuredPrice);
            Assert.AreEqual(.46m, ingredient3MeasuredPrice);
        }
        public ActionResult ResetSellingPrice()
        {
            var t    = new DatabaseAccess();
            var rest = new MakeRESTCalls();

            currentIngredient.sellingPrice = rest.GetItemResponse(currentIngredient).salePrice;
            t.updateAllTables(currentIngredient, currentRecipe);
            return(Redirect("/home/ingredient?name=" + currentIngredient.name + "&measurement=" + currentIngredient.measurement));
        }
Пример #15
0
        public void TestListOfItemResponsesNoWeight()
        {
            var rest     = new MakeRESTCalls();
            var i        = new Ingredient("Bread Flour");
            var expected = new List <Ingredient>();
            var actual   = rest.GetListItemResponseNoSellingWeights(i);

            Assert.AreEqual(expected, actual); //this is just to make sure actual is giving me what i want... it is
        }
Пример #16
0
        public void TestListOfItemResponsesNoWeightVanillaExtractFirstLetterCapitalized()
        {
            var rest     = new MakeRESTCalls();
            var i        = new Ingredient("Vanilla Extract");
            var expected = new List <Ingredient>();
            var actual   = rest.GetListItemResponseNoSellingWeights(i);

            Assert.AreEqual(expected, actual);
        }
Пример #17
0
        public void TestListOfItemResponsesNoWeightVanillaExtract()
        {
            var rest     = new MakeRESTCalls();
            var i        = new Ingredient("vanilla extract");
            var expected = new List <Ingredient>();
            var actual   = rest.GetListItemResponseNoSellingWeights(i);

            Assert.AreEqual(expected, actual);
            //ok, this one is passing, but i don't want it to, i have to test capitalization
        }
        public void TestUpdatingSellingPrice2()
        {
            var t    = new DatabaseAccess();
            var dbD  = new DatabaseAccessDensities();
            var rest = new MakeRESTCalls();
            var i    = new Ingredient("Bread Flour")
            {
                ingredientId  = 1,
                sellingWeight = "5 pound"
            };
            var i2 = new Ingredient("Softasilk Cake Flour")
            {
                ingredientId  = 2,
                sellingWeight = "32 ounces"
            };
            var i3 = new Ingredient("Pillsbury All-Purpose Flour")
            {
                ingredientId  = 3,
                sellingWeight = "2 pounds"
            };
            var i4 = new Ingredient("Baking Powder")
            {
                ingredientId  = 4,
                sellingWeight = "10 ounces"
            };
            var response = new ItemResponse()
            {
                name = "King Arthur Flour Unbleached Bread Flour, 5.0 LB"
            };
            var response2 = new ItemResponse()
            {
                name = "Pillsbury Softasilk: Enriched Bleached Cake Flour, 32 Oz"
            };
            var response3 = new ItemResponse()
            {
                name = "Pillsbury Best All Purpose Bleached Enriched Pre-Sifted Flour, 2 lb"
            };
            var respone4 = new ItemResponse()
            {
                name = "Rumford Premium Aluminum-Free Baking Powder, 10 oz"
            };

            t.initializeDatabase();
            dbD.insertIngredientDensityData(i);
            dbD.insertIngredientDensityData(i2);
            dbD.insertIngredientDensityData(i3);
            dbD.insertIngredientDensityData(i4);
            var myIngInfo = dbD.queryDensitiesTableAllRows();

            Assert.AreEqual(4, myIngInfo.Count());
            Assert.AreEqual(rest.GetItemResponse(i), myIngInfo[0].sellingPrice);
            Assert.AreEqual(rest.GetItemResponse(i2), myIngInfo[1].sellingPrice);
            Assert.AreEqual(rest.GetItemResponse(i3), myIngInfo[2].sellingPrice);
            Assert.AreEqual(rest.GetItemResponse(i4), myIngInfo[3].sellingPrice);
        }
Пример #19
0
        public void TestSimiliarities6()
        {
            var rest = new MakeRESTCalls();
            //var expected = true;
            var expected = false;
            var actual   = rest.SimilaritesInStrings("All-Purpose FLour", "all purpose flour");

            Assert.AreEqual(expected, actual);
            //this isn't passing becasue of the - in All-Purpose... that's something that may need to be fixed later on...
            //or just have a comment in the
        }
        public void insertIngredientIntoDensityInfoDatabase(Ingredient i)
        {
            var rest = new MakeRESTCalls();
            var db   = new DatabaseAccess();

            insertDensityTextFileIntoDensityInfoDatabase();
            var myUpdatedDensityInfoTable          = queryDensityInfoTable();
            var myMilkAndEggDensityInfoIngredients = new List <Ingredient>();

            foreach (var ingredient in myUpdatedDensityInfoTable)
            {
                if (ingredient.name.ToLower().Contains("milk") || ingredient.name.ToLower().Contains("egg"))
                {
                    myMilkAndEggDensityInfoIngredients.Add(ingredient);
                }
            }
            var countSimilarIngredients = 0;

            foreach (var ingredient in myUpdatedDensityInfoTable)
            {
                if (i.typeOfIngredient.ToLower().Contains("milk") || i.typeOfIngredient.ToLower().Contains("egg"))
                {
                    foreach (var dairyOrEggIngredient in myMilkAndEggDensityInfoIngredients)
                    {
                        if (i.typeOfIngredient == dairyOrEggIngredient.name)
                        {
                            countSimilarIngredients++;
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    if (rest.SimilaritesInStrings(i.typeOfIngredient, ingredient.name))
                    {
                        countSimilarIngredients++;
                        break;
                    }
                }
            }
            if (countSimilarIngredients == 0)
            {
                var commandText = @"Insert into densityInfo (ingredient, density) values (@ingredient, @density);";
                db.executeVoidQuery(commandText, cmd => {
                    cmd.Parameters.AddWithValue("@ingredient", i.typeOfIngredient);
                    cmd.Parameters.AddWithValue("@density", i.density);
                    return(cmd);
                });
            }
            //all this is doing is determining if the density table already has an ingredient with said name, if so, then it won't add it, if the table doesn't have that name, it will insert it with the density
            var myDensityInfoDatabase = queryDensityInfoTable();
        }
        public Ingredient ReturnCurrentIngredientFromQueriedItemResponse(string itemresponsename, string itemresponsesaleprice)
        {
            var rest = new MakeRESTCalls();
            var currentItemResponse = new ItemResponse();

            currentItemResponse.name      = itemresponsename;
            currentItemResponse.salePrice = decimal.Parse(itemresponsesaleprice);
            currentIngredient             = rest.SplitItemResponseName(currentItemResponse);
            return(currentIngredient);
            //now i want to autopopuate the fields of name, density, selling price, selling weight...
            //i can give an attempt of guessing type by seeing if it matches any types... after all it's not final if i can put it as the placeholder or if
            //for now, we can just do placeholders...
        }
        public decimal queryDensityTableRowDensityValueByName(Ingredient i)
        {
            var rest         = new MakeRESTCalls();
            var db           = new DatabaseAccess();
            var myIngredient = new Ingredient();
            var commandTextQueryTableRowByName = string.Format(@"SELECT * FROM densityInfo WHERE ingredient='{0}';", i.typeOfIngredient);

            db.queryItems(commandTextQueryTableRowByName, reader => {
                myIngredient.name    = (string)reader["ingredient"];
                myIngredient.density = (decimal)reader["density"];
                return(myIngredient);
            });
            return(myIngredient.density);
        }
Пример #23
0
        public void TestParseItemResponseToIngredient()
        {
            var rest     = new MakeRESTCalls();
            var expected = new Ingredient("Pillsbury Bread Flour")
            {
                sellingWeight = "5 lb", sellingPrice = 2.64m
            };
            var itemResponse = new ItemResponse()
            {
                name = "Pillsbury Bread Flour 5 lb", salePrice = 2.64m
            };
            var actual = rest.SplitItemResponseName(itemResponse);

            Assert.AreEqual(expected.name, actual.name);
            Assert.AreEqual(expected.sellingPrice, actual.sellingPrice);
            Assert.AreEqual(expected.sellingWeight, actual.sellingWeight);
        }
        public void TestPricePerOunce()
        {
            var t    = new DatabaseAccess();
            var dbD  = new DatabaseAccessDensities();
            var rest = new MakeRESTCalls();
            var i    = new Ingredient("King Arthur Bread Flour")
            {
                ingredientId  = 1,
                sellingWeight = "5 lb"
            };
            var response = new ItemResponse()
            {
                name = "King Arthur Flour Unbleached Bread Flour, 5.0 LB"
            };

            t.initializeDatabase();
            dbD.insertIngredientDensityData(i);
            var myIngInfo = dbD.queryDensitiesTableAllRows();

            Assert.AreEqual(.0525m, myIngInfo[0].pricePerOunce);
        }
Пример #25
0
        public void TestGetListOfItemResponses()
        {
            var t    = new DatabaseAccess();
            var dbI  = new DatabaseAccessIngredient();
            var rest = new MakeRESTCalls();
            var r    = new Recipe("bread")
            {
                id = 1
            };
            var i = new Ingredient("bread flour")
            {
                ingredientId = 1, recipeId = 1, measurement = "6 cups", sellingWeight = "5 lb"
            };

            t.initializeDatabase();
            t.insertIngredientIntoAllTables(i, r);
            var myIngredients       = dbI.queryAllIngredientsFromIngredientTable();
            var listOfItemResponses = rest.GetListItemResponses(i);

            Assert.AreEqual(4, listOfItemResponses.Count());
            Assert.AreEqual(10308169, myIngredients[0].itemId);
            Assert.AreEqual(10308169, listOfItemResponses[0].itemId);
            Assert.AreEqual(true, listOfItemResponses[0].name.Contains(i.sellingWeight));
        }
        public ActionResult Recipe(string name)
        {
            var rest = new MakeRESTCalls();
            var db   = new DatabaseAccess();
            var dbI  = new DatabaseAccessIngredient();
            var dbD  = new DatabaseAccessDensityInformation();
            var dbC  = new DatabaseAccessConsumption();

            if (string.IsNullOrEmpty(name))
            {
                return(Redirect("/home/RecipeBox"));
            }
            name = name.Trim();
            var distinctIngredientNamesSorted     = dbI.myDistinctIngredientNamesSorted();
            var distinctIngredientClassifications = dbI.myDistinctIngredientClassificationsSorted();
            var distinctIngredientTypes           = dbI.myDistinctIngredientTypesSorted();

            myDatabaseRecipe          = getRecipes().First(x => x.name == name);
            currentRecipe             = myDatabaseRecipe;
            ViewBag.currentingredient = currentIngredient;
            if (distinctIngredientNamesSorted.Count() == 0 || distinctIngredientNamesSorted == null)
            {
                ViewBag.ingredientnames = new List <string>();
            }
            else
            {
                ViewBag.ingredientnames = distinctIngredientNamesSorted;
            }
            if (distinctIngredientTypes.Count() == 0 || distinctIngredientTypes == null)
            {
                ViewBag.types = new List <string>();
            }
            else
            {
                ViewBag.types = distinctIngredientTypes;
            }
            if (distinctIngredientClassifications.Count() == 0 || distinctIngredientClassifications == null)
            {
                ViewBag.classifications = new List <string>();
            }
            else
            {
                ViewBag.classifications = distinctIngredientClassifications;
            }

            ViewBag.distinctsellingweights = dbC.getListOfDistinctSellingWeights();
            ViewBag.currentrecipe          = currentRecipe;
            ViewBag.recipeboxcount         = getRecipes().Count();
            //ViewBag.distinctingredienttypes = dbD.getListOfIngredientTypesFromDensityTable();
            if (!string.IsNullOrEmpty(currentIngredient.name))
            {
                if (string.IsNullOrEmpty(currentIngredient.measurement))
                {
                    ViewBag.itemresponselist = rest.GetListItemResponseNoSellingWeights(currentIngredient);
                }
                else
                {
                    ViewBag.itemresponselist         = rest.GetListItemResponses(currentIngredient);
                    ViewBag.itemresponselistcombined = rest.CombineItemResponses(currentIngredient);
                }
            }
            else
            {
                ViewBag.itemresponselist         = new List <ItemResponse>();
                ViewBag.itemresponselistNoWeight = new List <ItemResponse>();
            }
            return(View());

            /*
             * foreach of these item responses in the list of item responses i think it would be wise to have an
             * algorithm to filter out the top 2 prices (or put them at the end of the list and gray them out so they're visible but not prominent...
             * there's a product of 6 5 lb bags of king arthur organic unbleached flour, but in the itemr esponse name, it doesn't give any specification of packs in it's name, so my algorithm wouldn't be able to do anything with it
             * unless i took the largest price and divided it by the average of the other prices and compared them, seeing if it was a pack that way...
             */
        }
        public void UpdateIngredient(Ingredient i)
        {
            var db   = new DatabaseAccess();
            var rest = new MakeRESTCalls();

            if (i.sellingPrice == 0m)
            {
                myItemResponse = rest.GetItemResponse(i);
            }
            if (i.sellingPrice == 0m && (!i.classification.ToLower().Contains("dairy")) || (!i.classification.ToLower().Contains("egg")))
            {
                if (i.itemId == 0)
                {
                    myItemResponse = returnItemResponse(i);
                    i.itemId       = myItemResponse.itemId;
                }
                if (string.IsNullOrEmpty(i.itemResponseName))
                {
                    i.itemResponseName = myItemResponse.name;
                }
                if (i.sellingPrice == 0m)
                {
                    i.sellingPrice = myItemResponse.salePrice;
                }
            }
            if ((i.classification.ToLower().Contains("dairy")) || (i.classification.ToLower().Contains("egg")))
            {
                i.itemResponseName = " ";
                if (string.IsNullOrEmpty(i.classification))
                {
                    i.classification = " ";
                }
                if (i.expirationDate == null)
                {
                    i.expirationDate = new DateTime();
                }
            }
            if (i.priceOfMeasuredConsumption == 0)
            {
                i.priceOfMeasuredConsumption = MeasuredIngredientPrice(i);
            }
            if (string.IsNullOrEmpty(i.classification))
            {
                i.classification = " ";
            }
            var myIngredientId = i.ingredientId;
            var commandText    = @"update ingredients set name=@name, 
                                measurement=@measurement,
                                recipe_id=@recipeId, 
                                price_measured_ingredient=@price_measured_ingredient, 
                                item_id=@item_id, 
                                ingredient_type=@ingredient_type, 
                                ingredient_classification=@ingredient_classification, 
                                item_response_name=@item_response_name, 
                                expiration_date=@expiration_date 
                                where ing_id=@ing_id AND name=@name;";

            db.executeVoidQuery(commandText, cmd => {
                cmd.Parameters.AddWithValue("@name", i.name);
                cmd.Parameters.AddWithValue("@measurement", i.measurement);
                cmd.Parameters.AddWithValue("@recipeId", i.recipeId);
                cmd.Parameters.AddWithValue("@ingredientId", i.ingredientId);
                cmd.Parameters.AddWithValue("@price_measured_ingredient", i.priceOfMeasuredConsumption);
                cmd.Parameters.AddWithValue("@item_id", i.itemId);
                cmd.Parameters.AddWithValue("@ingredient_type", i.typeOfIngredient);
                cmd.Parameters.AddWithValue("@ing_id", i.ingredientId);
                cmd.Parameters.AddWithValue("@ingredient_classification", i.classification);
                cmd.Parameters.AddWithValue("@item_response_name", i.itemResponseName);
                cmd.Parameters.AddWithValue("@expiration_date", convertDateToStringMMDDYYYY(i.expirationDate));
                return(cmd);
            });
        }
        public ItemResponse returnItemResponse(Ingredient i)
        {
            var rest = new MakeRESTCalls();

            return(rest.GetItemResponse(i));
        }