コード例 #1
0
        // GET: Recipes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            var user = await GetCurrentUserAsync();

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

            var recipe = await _context.Recipes.Include(r => r.RecipeType).FirstOrDefaultAsync(r => r.RecipeId == id);

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

            recipe.RecipeIngredients = _context.RecipeIngredients.Include(ing => ing.Ingredient).Where(ing => ing.RecipeId == recipe.RecipeId).ToList();

            DetailRecipeViewModel viewModel = new DetailRecipeViewModel(
                _context.Ingredients.ToList(),
                recipe.RecipeIngredients.ToList());

            viewModel.Name        = recipe.Name;
            viewModel.RecipeNotes = recipe.RecipeNotes;
            viewModel.RecipeId    = recipe.RecipeId;
            viewModel.RecipeType  = recipe.RecipeType;

            return(View(viewModel));
        }
コード例 #2
0
        public DetailRecipePage(int selectedRecipeId)
        {
            InitializeComponent();
            var viewModel = new DetailRecipeViewModel(selectedRecipeId);

            BindingContext = viewModel;
        }
コード例 #3
0
        /// <summary>
        /// Shows an indepth view of the recipe so people can see all the details
        /// </summary>
        /// <param name="recipeId"></param>
        /// <returns>Tf there is ingredients to the recipe, it returns the detailed view</returns>
        public IActionResult Detail(int recipeId)
        {
            //Get the list of Ingredients
            IList<Ingredient> editIngredients = context.Ingredients.Include(p => p.Recipe).Where(p => p.RecipeID == recipeId).ToList();
            if(editIngredients.Count() != 0)
            {
                DetailRecipeViewModel detailRecipeViewModel = new DetailRecipeViewModel(editIngredients);
                return View(detailRecipeViewModel);
            }
            else
            {
                return Redirect("/");
            }
            

        }