コード例 #1
0
        public async Task <IActionResult> OnGet(int productId)
        {
            Product = await repository.GetProductAsync(productId);

            if (Product == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            return(Page());
        }
コード例 #2
0
        public async Task <ActionResult <ProductDto> > GetProduct(int id)
        {
            var product = await repository.GetProductAsync(id);

            if (product == null)
            {
                return(NotFound());
            }
            else
            {
                return(mapper.Map <ProductDto>(product));
            }
        }
コード例 #3
0
ファイル: Edit.cshtml.cs プロジェクト: Marcin-Stanczyk/Juicer
        public async Task <IActionResult> OnGet(int?productId)
        {
            Categories = htmlHelper.GetEnumSelectList <CategoryType>();

            if (productId.HasValue)
            {
                Product = await repository.GetProductAsync(productId.Value);

                if (Product == null)
                {
                    return(RedirectToPage("./NotFound"));
                }
            }
            else
            {
                Product = new Product();
            }

            return(Page());
        }
コード例 #4
0
        public async Task <IActionResult> OnGet(int productId)
        {
            Product = await repository.GetProductAsync(productId);

            if (Product == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            var recipes = await repository.GetAllRecipesAsync();

            var recipesWithThisProduct = recipes.Where(r => r.Ingredients.Any(p => p.Product.Name == Product.Name));

            Recipes = mapper.Map <RecipeDto[]>(recipesWithThisProduct);

            return(Page());
        }