Ejemplo n.º 1
0
        public async Task <MealVM> GetMealByIdAsync(Guid userId, Guid mealId)
        {
            var meal = await _mealRepository.GetMealByIdAsync(mealId);

            if (meal == null)
            {
                return(null);
            }

            var ingredients = await _mealIngredientRepository.GetMealIngredientsForMealAsync(mealId);

            var mealVM = _mapper.Map <MealVM>(new MealWithIngredients(meal, ingredients));

            if (meal.CreatorId != userId)
            {
                if (await _favouritesRepository.ContainsAsync(userId, mealId))
                {
                    mealVM.IsFavourite = true;
                }
                else
                {
                    mealVM.IsFavourite = false;
                }
            }

            return(mealVM);
        }