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);
        }
        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));
        }
        public ItemResponse returnItemResponse(Ingredient i)
        {
            var rest = new MakeRESTCalls();

            return(rest.GetItemResponse(i));
        }
        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);
            });
        }