コード例 #1
0
ファイル: DayManager.cs プロジェクト: Zaicew/CountIt
        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));
        }
コード例 #2
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);
        }