示例#1
0
        public void AddProductsToMealsMixed(MealManager mealManager, ItemManager itemManager, ItemService itemService)
        {
            Random rnd = new Random();
            double howManyGramsOfProduct = 0;

            double[] grams = { 20.3, 30.9, 40.3, 50.1, 60.8, 70.9, 80.4, 90.8 };
            foreach (var item in _dayService.Items)
            {
                for (int i = 0; i < item.MealList.Count; i++)
                {
                    var mealHolder = item.MealList[i];
                    var itemHolder = new ItemInMeal(itemService.Items[rnd.Next(1, itemService.Items.Count)], grams[rnd.Next(1, 8)]);

                    mealHolder.ProductsInMeal.Add(itemHolder);
                    howManyGramsOfProduct = grams[rnd.Next(1, 7)];


                    mealHolder.TotalCarbs   += Math.Round(itemHolder.Carb * howManyGramsOfProduct / 100, 2);
                    mealHolder.TotalFat     += Math.Round(itemHolder.Fat * howManyGramsOfProduct / 100, 2);
                    mealHolder.TotalKcal    += Math.Round(itemHolder.Kcal * howManyGramsOfProduct / 100, 2);
                    mealHolder.TotalProtein += Math.Round(itemHolder.Protein * howManyGramsOfProduct / 100, 2);

                    item.TotalCarbs   += Math.Round(mealHolder.TotalCarbs, 2);
                    item.TotalFat     += Math.Round(mealHolder.TotalFat, 2);
                    item.TotalKcal    += Math.Round(mealHolder.TotalKcal, 2);
                    item.TotalProtein += Math.Round(mealHolder.TotalProtein, 2);
                }
            }
        }
示例#2
0
        public void AddNewMealMixed(MealManager _mealManager, ItemManager _itemManager, DayService _dayService)
        {
            Random rnd = new Random();

            string[] names = { "Breakfast", "Lunch", "Dinner", "Evening food :)" };
            foreach (var item in _dayService.Items)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    item.MealList.Add(new Meal(names[i], rnd.Next(1, 10)));
                }
            }
        }
示例#3
0
        public ItemInMeal GetItemFromMeal(Meal meal, MealManager mealManager)
        {
            int choosenIdOfItem;

            do
            {
                Console.Clear();
                Console.WriteLine("Please type product ID, which you want to delete from meal...");
                mealManager.ShowAllProductsFromMeal(meal);
            }while (!int.TryParse(Console.ReadLine(), out choosenIdOfItem) || !meal.ProductsInMeal.Contains(meal.ProductsInMeal.FirstOrDefault(s => s.Id == choosenIdOfItem)));
            Console.WriteLine("item id to delete meal : " + choosenIdOfItem);
            return(meal.ProductsInMeal.FirstOrDefault(s => s.Id == choosenIdOfItem));
        }
示例#4
0
        public int RemoveProductFromMeal(MealManager _mealManager)
        {
            var dayHolder        = GetDay();
            var mealHolder       = GetMealFromDay(dayHolder);
            var itemInMealHolder = GetItemFromMeal(mealHolder, _mealManager);

            return(_dayService.RemoveProductFromMeal(itemInMealHolder, mealHolder, dayHolder));

            //mealHolder.ProductsInMeal.Remove(itemInMealHolder);
            //_dayService.RecalculateMacrosInMeal(mealHolder);
            //_dayService.RecalculateMacrosInDay(dayHolder);

            //Console.WriteLine("Total Carbs: " + mealHolder.TotalCarbs);
            //Console.WriteLine("Total fat: " + mealHolder.TotalFat);
            //Console.WriteLine("Total kcal: " + mealHolder.TotalKcal);
            //Console.WriteLine("Total protein: " + mealHolder.TotalProtein);
        }
示例#5
0
        public void RemoveProductFromMeal(MealManager _mealManager)
        {
            var dayHolder  = GetDay();
            var mealHolder = GetMealFromDay(dayHolder);
            int choosenIdOfItem;

            do
            {
                Console.Clear();
                Console.WriteLine("Please type product ID, which you want to delete from meal...");
                _mealManager.ShowAllProductsFromMeal(mealHolder);
            }while (!int.TryParse(Console.ReadLine(), out choosenIdOfItem) || !mealHolder.ProductsInMeal.Contains(mealHolder.ProductsInMeal.FirstOrDefault(s => s.Id == choosenIdOfItem)));
            Console.WriteLine("item id to delete meal : " + choosenIdOfItem);
            var itemInMealHolder = mealHolder.ProductsInMeal.FirstOrDefault(s => s.Id == choosenIdOfItem);

            mealHolder.ProductsInMeal.Remove(itemInMealHolder);
            RecalculateMacrosInMeal(mealHolder);
            RecalculateMacrosInDay(dayHolder);

            Console.WriteLine("Total Carbs: " + mealHolder.TotalCarbs);
            Console.WriteLine("Total fat: " + mealHolder.TotalFat);
            Console.WriteLine("Total kcal: " + mealHolder.TotalKcal);
            Console.WriteLine("Total protein: " + mealHolder.TotalProtein);
        }