コード例 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            recipe = await recipesService.FindAsync(Id.GetValueOrDefault()) ?? new Recipe();

            recipe.Id   = Id.GetValueOrDefault();
            recipe.Name = recipe.Name;

            await recipesService.SaveAsync(recipe);

            return(RedirectToPage("/Recipe", new { id = Id }));
        }
コード例 #2
0
        public async Task <IActionResult> GetRecipeById(Guid id)
        {
            var userId = Guid.Parse(User.FindFirstValue(KnownClaims.UserId));
            var recipe = await recipesService.FindAsync(id);

            if (recipe == null || (recipe.IsPrivate && recipe.UserId != userId))
            {
                return(NotFound());
            }

            var mappedRecipe = mapper.Map <RecipeDetailsDTO>(recipe);

            return(Ok(mappedRecipe));
        }
コード例 #3
0
        public async Task <IActionResult> AddRecipeToCart(Guid recipeId)
        {
            if (recipeId == null)
            {
                return(BadRequest());
            }

            var recipe = await recipesService.FindAsync(recipeId);

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

            var userId   = Guid.Parse(User.FindFirstValue(KnownClaims.UserId));
            var cartItem = CartItem.Create(userId, recipe);
            await cartService.AddAsync(cartItem);

            return(new StatusCodeResult((int)HttpStatusCode.Created));
        }
コード例 #4
0
 public async Task OnGetAsync()
 {
     Recipe = await recipesService.FindAsync(Id.GetValueOrDefault()) 
         ?? new Recipe();
 }
コード例 #5
0
 //public void OnGet() --> mozne vyuzit async verziu
 public async Task OnGetAsync() //nezov metody je suportovany: OnGet alebo OnGetAsync
 {
     Recipe = await _recipesService.FindAsync(Id.GetValueOrDefault()) ?? new Recipe();
 }