public IActionResult SaveFood(string name, string serving_unit, float serving_qty, int mealId, int numberOfServings)
        {
            User user   = authProvider.GetCurrentUser();
            int  userId = user.Id;

            ApiDAL api           = new ApiDAL();
            string jsonNutrition = api.getNutritionInfo(name);

            if (jsonNutrition == "EXCEPTION_THROWN")
            {
                return(RedirectToAction("FoodResults", "Dashboard"));
            }
            FoodItem foodItem = JsonConvert.DeserializeObject <FoodItem>(jsonNutrition);
            Food     food     = foodItem.foods[0];

            food.Name         = name;
            food.serving_unit = serving_unit;
            food.serving_qty  = serving_qty;

            if (mealId == 0)
            {
                dal.SaveItemToUserFoodLog(userId, food);
            }
            else
            {
                dal.SaveItemToUserFoodLog(userId, food, mealId, numberOfServings);
            }


            return(RedirectToAction("Index", "Dashboard"));
        }
        public IActionResult ViewFoodDetail(string name, string imgurl, string serving_unit, float serving_qty)
        {
            ApiDAL   api           = new ApiDAL();
            string   jsonNutrition = api.getNutritionInfo(name);
            FoodItem foodItem      = JsonConvert.DeserializeObject <FoodItem>(jsonNutrition);

            foodItem.foods[0].Name         = name;
            foodItem.foods[0].Imgurl       = imgurl;
            foodItem.foods[0].serving_qty  = serving_qty;
            foodItem.foods[0].serving_unit = serving_unit;
            return(View(foodItem));
        }
        public IActionResult FoodResults(FoodPreview foodSearch)
        {
            ApiDAL api     = new ApiDAL();
            string jsonRes = api.searchForFood(foodSearch.Name);


            JsonResponseModel jsonObj = JsonConvert.DeserializeObject <JsonResponseModel>(jsonRes);

            var brandedResults = jsonObj.branded;
            var commonResults  = jsonObj.common;

            SearchResults res = new SearchResults();

            res.Name = foodSearch.Name;


            foreach (var i in brandedResults)
            {
                FoodPreview preview = new FoodPreview();
                preview.Name            = i.food_name;
                preview.PhotoUrl        = i.photo.thumb;
                preview.ServingQuantity = i.serving_qty;
                preview.ServingUnit     = i.serving_unit;
                res.FoodSearchResults.Add(preview);
            }

            foreach (var i in commonResults)
            {
                FoodPreview preview = new FoodPreview();
                preview.Name            = i.food_name;
                preview.PhotoUrl        = i.photo.thumb;
                preview.ServingQuantity = i.serving_qty;
                preview.ServingUnit     = i.serving_unit;
                res.FoodSearchResults.Add(preview);
            }

            return(View(res));
        }