Exemple #1
0
        public IActionResult Details(int id)
        {
            var recipe = recipeService.GetRecipe(id);

            if (recipe == null)
            {
                return(NotFound());
            }

            var ingredients = context.IngredientsInRecipes
                              .Include(i => i.Ingredient)
                              .Where(i => i.RecipeId == id)
                              .Select(ingredient => new IngredientWithQuantity()
            {
                Ingredient = ingredient.Ingredient,
                Quantity   = ingredient.Quantity
            });

            var recipePicture = recipeService.GetRecipePicture(recipe.Id);

            if (recipePicture != null)
            {
                ViewData["RecipePicturePath"] = recipeService.GetPicturePath(recipePicture);
            }

            var currentUserId = userManager.GetUserId(User);

            var vm = new RecipeDetailsViewModel()
            {
                Recipe      = recipe,
                Ingredients = ingredients,
                IsFavouritedByCurrentUser = recipeService.CheckIfRecipeIsFavouritedByUser(recipe, currentUserId),
                NumberOfLikes             = recipeService.GetNumberOfLikes(id)
            };

            return(View(vm));
        }