Пример #1
0
        public async Task <ActionResult <UserFoodScoreDTO> > GetUserFoodScore(GetUserFoodsDTO getUserFoods)
        {
            var userFoods = await foodRepository.GetUserFoodsByDate(getUserFoods.UserId, getUserFoods.Date);

            var userFoodScore = new UserFoodScoreDTO
            {
                Calories = 0,
                Protein  = 0,
                Fat      = 0,
                Carbs    = 0,
                Alcohol  = 0,
                Fiber    = 0,
            };

            foreach (var userFood in userFoods)
            {
                userFoodScore.Calories += userFood.Food.Calories * userFood.Servings;
                userFoodScore.Protein  += userFood.Food.Protein * userFood.Servings;
                userFoodScore.Fat      += userFood.Food.Fat * userFood.Servings;
                userFoodScore.Carbs    += userFood.Food.Carbs * userFood.Servings;
                userFoodScore.Alcohol  += userFood.Food.Alcohol * userFood.Servings;
                userFoodScore.Fiber    += userFood.Food.Fiber * userFood.Servings;
            }

            return(new ActionResult <UserFoodScoreDTO>(userFoodScore));
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <FoodDTO> > > GetUserFoods(GetUserFoodsDTO getUserFoods)
        {
            var userFoods = await foodRepository.GetUserFoodsByDate(getUserFoods.UserId, getUserFoods.Date);

            return(new ActionResult <IEnumerable <FoodDTO> >(userFoods.Select(Mapper.ToFoodDTO)));
        }