Exemplo n.º 1
0
        public async Task <FoodResponse> GetFoodDetails(int foodId, int userId)
        {
            using (var scope = _mouthfeelContextFactory.CreateContext())
            {
                var food = await _mouthfeel.Foods.FindAsync(foodId);

                var images = await _images.DownloadImages(foodId);

                var sentiment = await GetFoodSentiment(foodId, userId);

                var toTry = await GetFoodToTryStatus(foodId, userId);

                var ingredients = await _ingredients.GetIngredients(foodId);

                var textures = await _attributes.GetVotes(foodId, userId, VotableAttributeType.Texture);

                var flavors = await _attributes.GetVotes(foodId, userId, VotableAttributeType.Flavor);

                var misc = await _attributes.GetVotes(foodId, userId, VotableAttributeType.Miscellaneous);

                if (food == null)
                {
                    throw new ErrorResponse(HttpStatusCode.NotFound, ErrorMessages.FoodNotFound, DescriptiveErrorCodes.FoodNotFound);
                }

                return(new FoodResponse(food, images, sentiment, toTry, ingredients, flavors, textures, misc));
            }
        }