public IActionResult Delete(int recipeId) { Recipe deletedRecipe = repository.DeleteRecipe(recipeId); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Name} was deleted"; } return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteRecipeById(int id) { var recipe = await _repository.GetRecipeById(id); if (recipe == null) { return(StatusCode(404, new { status = "not found", statusCode = 404, message = $"Recipe with id {id} is not found!" })); } _repository.DeleteRecipe(recipe); await _repository.SaveChanges(); return(StatusCode(200, new { status = "success", statusCode = 200, message = $"Recipe with id {id} is succesfully deleted!", deletedRecipe = recipe })); }
/// <summary> /// Removes a RecipeItem from the database and the product. /// </summary> /// <param name="r">The RecipeItem selected in the view that has to be deleted.</param> private void DeleteRecipeItem(RecipeItem r) { try { if (ActionToTake == "add") { ProductRecipeItems.Remove(r); } else { ProductRecipeItems.Remove(r); _recipeRepo.DeleteRecipe(r); } } catch (Exception e) { Console.WriteLine(e); throw; } }
private void DeleteProduct(Product product) { try { ObservableCollection <RecipeItem> recipeItemList = new ObservableCollection <RecipeItem>(_recipeRepo.GetRecipes() .Where(r => r.Product.ID.Equals(product.ID))); foreach (RecipeItem recipeItem in recipeItemList) { _recipeRepo.DeleteRecipe(recipeItem); } Products.Remove(product); _productRepo.DeleteProduct(product); MessageHandler.InvokeSuccessMessage(Resources.InformationDeleteProduct, Resources.InformationProductDeleted.Replace("{name}", product.Name)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public ActionResult Delete(int id) { _recipeRepo.DeleteRecipe(id); return(new JsonResult("")); }