Exemplo n.º 1
0
        public async Task<IActionResult> OnPost(int recipeId)
        {
            var recipe = await repository.GetRecipeAsync(recipeId);
            if (recipe == null)
                return RedirectToPage("./NotFound");

            repository.Delete(recipe);
            await repository.SaveChangesAsync();

            TempData["Message"] = $"{recipe.Name} deleted.";
            return RedirectToPage("./List");
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPost(int productId)
        {
            var product = await repository.GetProductAsync(productId);

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

            repository.Delete(product);
            await repository.SaveChangesAsync();

            TempData["Message"] = $"{product.Name} deleted.";
            return(RedirectToPage("./List"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Delete(int id)
        {
            var recipeToDelete = await repository.GetRecipeAsync(id);

            if (recipeToDelete == null)
            {
                return(NotFound($"Could not find recipe with id: {id}."));
            }

            repository.Delete(recipeToDelete);

            if (await repository.SaveChangesAsync())
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("Failed to delete the recipe."));
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Delete(int id)
        {
            var productToDelete = await repository.GetProductAsync(id);

            if (productToDelete == null)
            {
                return(NotFound($"Could not find product with id: {id}."));
            }

            repository.Delete(productToDelete);

            if (await repository.SaveChangesAsync())
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("Failed to delete the product."));
            }
        }