Ejemplo n.º 1
0
        private FullMeal CreateFullMeal(Meal meal)
        {
            var         amount   = meal.Foods.Sum(a => a.Amount);
            List <int>  foodIds  = meal.Foods.Select(e => e.FoodId).ToList();
            List <Food> foods    = foodDao.GetAllFoods().FindAll(food => foodIds.Contains(food.FoodID));
            double      calories = 0;
            double      carbs    = 0;
            double      protein  = 0;
            double      fat      = 0;

            foreach (var food in foods)
            {
                var amountTotal = meal.Foods.First(f => f.FoodId == food.FoodID).Amount;
                calories += UsefulAlgorithms.By3Rule(amountTotal, food.Calories, food.Amount);
                carbs    += UsefulAlgorithms.By3Rule(amountTotal, food.Carbs, food.Amount);
                protein  += UsefulAlgorithms.By3Rule(amountTotal, food.Protein, food.Amount);
                fat      += UsefulAlgorithms.By3Rule(amountTotal, food.Fat, food.Amount);
            }

            return(new FullMeal()
            {
                Amount = amount,
                MealId = meal.Id,
                Calories = calories,
                Carbs = carbs,
                Fat = fat,
                Protein = protein,
                Weigth = "g",
                Date = meal.Date
            });
        }
Ejemplo n.º 2
0
 public List <Food> GetAllFoods()
 {
     return(foodDao.GetAllFoods());
 }