예제 #1
0
        //shows menu after date and meal number selection
        private ActionResult GenerateMenuTwo()
        {
            ViewBag.ShowMessage = false;

            int mealNumber = int.Parse(Session["mealNumber"].ToString());
            List <Combination> combinationsList = SQLProcedures.GetSavedMealCombinations();

            combinationsList.Sort((x, y) => x.NumberOfMeals.CompareTo(y.NumberOfMeals));

            ViewBag.Combinations = new SelectList(combinationsList, "NumberOfMeals", "NumberOfMeals", mealNumber);

            string selectedCombDate = Session["selectedCombDate"].ToString();

            ViewBag.CombinationDate = selectedCombDate;

            double totalKcal = CalculateTotalKcal();

            //sorting food by type

            List <Food> foodList    = SQLProcedures.GetFood();
            List <Food> carbsList   = new List <Food>();
            List <Food> fatList     = new List <Food>();
            List <Food> proteinList = new List <Food>();

            foreach (Food food in foodList)
            {
                switch (food.Type)
                {
                case "Ugljikohidrat":
                    carbsList.Add(food);
                    break;

                case "Mast":
                    fatList.Add(food);
                    break;

                case "Bjelancevina":
                    proteinList.Add(food);
                    break;

                default:
                    break;
                }
            }

            List <MealRatio>    mealRatioList = SQLProcedures.GetMealRatioOfComboForNumberOfMeals(mealNumber);
            List <MenuMealData> menuMealsList = new List <MenuMealData>();
            Random rnd = new Random();

            for (int i = 0; i < mealNumber; i++)
            {
                MealRatio ratio            = mealRatioList.ElementAt(i);
                double    totalMealPortion = Math.Round(totalKcal * ratio.TotalPortion / 100, 2);
                double    fatPortion       = Math.Round(totalMealPortion * ratio.FatPortion / 100, 2);
                double    carbPortion      = Math.Round(totalMealPortion * ratio.CarbPortion / 100, 2);
                double    proteinPortion   = Math.Round(totalMealPortion * ratio.ProteinPortion / 100, 2);

                int    index    = rnd.Next(fatList.Count);
                Food   fat      = fatList.ElementAt(index);
                string fatUnits = CalculateUnitAmount(fat.IDFood, fatPortion);

                index = rnd.Next(carbsList.Count);
                Food   carbs     = carbsList.ElementAt(index);
                string carbUnits = CalculateUnitAmount(carbs.IDFood, carbPortion);

                index = rnd.Next(proteinList.Count);
                Food   protein      = proteinList.ElementAt(index);
                string proteinUnits = CalculateUnitAmount(protein.IDFood, proteinPortion);

                menuMealsList.Add(new MenuMealData
                {
                    MealName     = mealRatioList.ElementAt(i).Meal.Name,
                    CarbName     = carbs.Name,
                    CarbUnits    = carbUnits,
                    FatName      = fat.Name,
                    FatUnits     = fatUnits,
                    ProteinName  = protein.Name,
                    ProteinUnits = proteinUnits
                });
            }

            Session["menuMealsList"] = menuMealsList;
            return(View("GenerateMenuTwo", menuMealsList));
        }