Exemple #1
0
        public async Task <ActionResult <UserProfileDto> > GetProfile(int userId)
        {
            // NOTE: simple call, no need for separate query object
            var user = dbContext
                       .Set <User>()
                       .Include(u => u.Profile)
                       .First(u => u.Id == userId);

            var userDto = new UserProfileDto()
            {
                AllowedCalories = user.Profile?.AllowedCalories ?? 0
            };

            return(Ok(userDto));
        }
Exemple #2
0
        public async Task <ActionResult <MealDto> > GetMeal(long userId, long mealId)
        {
            var mealQuery =
                from u in dbContext.Set <User>()
                from m in u.Meals
                where u.Id == userId && m.Id == mealId
                select new MealDto()
            {
                Date        = m.Date,
                Calories    = m.Calories,
                Description = m.Description
            };

            var meal = mealQuery.First();

            return(Ok(meal));
        }