コード例 #1
0
        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());
        }
コード例 #2
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));
        }
コード例 #3
0
        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...
             */
        }