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 })); }
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)); }
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)); }
public async Task OnGetAsync() { Recipe = await recipesService.FindAsync(Id.GetValueOrDefault()) ?? new Recipe(); }
//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(); }