public ActionResult Delete(int id) { var recipeToDelite = db.FindRecipe(id); if (recipeToDelite == null) { return(HttpNotFound()); } var userId = User.Identity.GetUserId(); var isModerator = User.IsInRole("Moderator"); if (userId != null && userId != recipeToDelite.UserId && isModerator == false) { return(HttpNotFound()); } if (recipeToDelite.ImageUrl != null) { try { System.IO.File.Delete(HttpContext.Server.MapPath("~/Content/images/thumbnails/" + recipeToDelite.ImageUrl)); } catch { } } db.DeleteRecipe(recipeToDelite); db.Save(); return(RedirectToAction("Index", "Home")); }
public IActionResult DeleteRecipe(int recipeId) { if (!_recipeRepository.RecipeExists(recipeId)) { return(NotFound()); } var reviewsToDelete = _reviewRepository.GetReviewsOfARecipe(recipeId); var recipeToDelete = _recipeRepository.GetRecipe(recipeId); if (!ModelState.IsValid) { return(BadRequest()); } if (!_reviewRepository.DeleteReviews(reviewsToDelete.ToList())) { ModelState.AddModelError("", $"Something went wrong deleting reviews"); return(StatusCode(500, ModelState)); } if (!_recipeRepository.DeleteRecipe(recipeToDelete)) { ModelState.AddModelError("", $"Something went wrong deleting recipe {recipeToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public void DeleteRecipe(int recipeId) { if (recipeId > 0) { _recipeRepository.DeleteRecipe(recipeId); } }
public IActionResult DeleteData(RecipeFormViewModelData recipe) { RecipeItem newRecipe = new RecipeItem(); newRecipe.RecipeName = recipe.RecipeName; newRecipe.ServingSize = recipe.ServingSize; newRecipe.Description = recipe.Description; newRecipe.RecipeId = recipe.RecipeId; Ingredient newIngredient = new Ingredient(); newIngredient.IngredientName = recipe.Ingredient; newIngredient.IngredientId = recipe.RecipeId; Equipment newEquipment = new Equipment(); newEquipment.EquipmentName = recipe.Equipment; newEquipment.EquipmentId = recipe.RecipeId; newRecipe.Instructions = recipe.Instructions; Review newReview = new Review(); newReview.ReviewText = recipe.Review; newReview.ReviewId = recipe.RecipeId; repository.DeleteRecipe(newRecipe); repository.DeleteReview(newReview); repository.DeleteIngredient(newIngredient); repository.DeleteEquipment(newEquipment); return(RedirectToAction("DataPage", "Home")); }
public IActionResult Delete(Recipe recipe) { if (ModelState.IsValid) { repo.DeleteRecipe(recipe); } return(RedirectToAction("Index", "Recipe")); }
public IActionResult Delete(int recipeId) { var applicationUserId = _userManager.GetUserId(HttpContext.User); _recipeRepository.DeleteRecipe(recipeId); return(RedirectToAction("userrecipes", "home", new { userId = applicationUserId })); }
internal bool DeleteRecipe(Recipe recipe) { if (recipe == null) { return(false); } _recipeRepository.DeleteRecipe(recipe); _recipeRepository.SaveChanges(); return(true); }
public IActionResult Delete(int recipeId) { AddRecipe deletedRecipe = repository.DeleteRecipe(recipeId); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Name} was deleted!"; } return(RedirectToAction(nameof(Index))); }
public ViewResult Delete(int id) { Recipe deletedProduct = repository.DeleteRecipe(id); if (deletedProduct != null) { TempData["message"] = $"{deletedProduct.Name} was deleted"; } return(View()); }
public IActionResult Delete(int recipeId) { Recipe deleteRecipe = Repository.DeleteRecipe(recipeId); if (deleteRecipe != null) { TempData["message"] = $"{deleteRecipe.RecipeName} has been deleted"; } return(RedirectToAction("Index")); }
public IActionResult Delete(int recipeId) { Recipe deletedRecipe = recipeRepository.DeleteRecipe(recipeId); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Name} was deleted!"; } return(RedirectToAction("RecipeList", controllerName: "Home")); }
public IActionResult Delete(int id) { Recipes deletedRecipe = repository.DeleteRecipe(id); if (deletedRecipe != null) { TempData["message"] = $"Recipe {deletedRecipe.Name} was deleted"; } return(RedirectToAction("Index")); }
public IActionResult Delete(int recipeId) { Recipe deletedRecipe = repository.DeleteRecipe(recipeId); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.RecipeName} is deleted."; } return(RedirectToAction("RecipeList", "Home")); }
public ActionResult Delete(int recipeId) { Recipe deletedRecipe = repository.DeleteRecipe(recipeId); if (deletedRecipe != null) { TempData["message"] = string.Format("Рецепт \"{0}\" был удален", deletedRecipe.Name); } return(RedirectToAction("Index")); }
public IActionResult Delete(int recipeId) { Recipe deletedProduct = repository.DeleteRecipe(recipeId); if (deletedProduct != null) { TempData["message"] = $"{deletedProduct.RecipeName} was deleted!"; } return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteRecipe(int recipeId) { var successful = await _recipeRepo.DeleteRecipe(recipeId); if (successful) { return(Ok()); } return(BadRequest()); }
public IActionResult Delete(int id) { Recipe deletedRecipe = repository.DeleteRecipe(id); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Title} was deleted!"; } return(RedirectToAction("../Home/RecipeList")); }
public IActionResult Delete(int id) { Recipe deletedRecipe = recipeRepository.DeleteRecipe(id); if (deletedRecipe != null) { var msg = "swal('Success', '" + deletedRecipe.RecipeName.ToString() + " has been deleted" + "','success')" + ""; TempData["message"] = msg; } return(RedirectToAction("RecipeList")); }
public ActionResult <Recipe> deleteRecipe(Recipe recipe) { try { _recipeRepository.DeleteRecipe(recipe); } catch (Exception) { throw; } return(recipe); }
public IActionResult Delete([FromBody] Recipe recipe) { try { _recipeRepository.DeleteRecipe(recipe, true); return(Ok()); } catch (Exception e) { _logger.LogError(e, e.Message); return(StatusCode(500)); } }
public ActionResult DeleteRecipe(int recipeId) { var recipeFromRepo = _recipeRepository.GetRecipe(recipeId); if (recipeFromRepo == null) { return(NotFound()); } _recipeRepository.DeleteRecipe(recipeFromRepo); _recipeRepository.Save(); return(NoContent()); }
public async Task <ActionResult> DeleteRecipeAsync(int recipeId) { if (recipeId <= 0) { return(BadRequest("Invalid data!")); } if (await _recipeRepository.DeleteRecipe(recipeId)) { return(Ok()); } return(BadRequest("Upps..ceva nu a mers!")); }
public ActionResult DeleteRecipe(int id) { Recipe recipe = _recipeRepository.GetRecipeById(id); if (recipe == null) { return(NotFound("Recipe Not Found")); } var response = _recipeRepository.DeleteRecipe(recipe); if (response == "success") { return(Ok(StatusCodes.Status200OK)); } return(StatusCode(StatusCodes.Status500InternalServerError, response)); }
public ViewResult DeleteRecipe(int rId) { List <CookingStep> ls = cookingStepRepository.CookingSteps.Where(x => x.RecipeId == rId).ToList(); foreach (CookingStep cs in ls) { cookingStepRepository.DeleteCookingStep(cs.CookingStepId); } Recipe deletedRecipe = recipeRepository.DeleteRecipe(rId); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Name} has been deleted!"; } return(View("../Home/RecipeList", recipeRepository.Recipes)); }
public async Task <IActionResult> Delete(int recipeId) { Recipe recipe = repository.Recipes.FirstOrDefault(r => r.RecipeID == recipeId); var LoggedUser = await userManager.GetUserAsync(User); if (recipe.UserId == LoggedUser.UserName) { Recipe deletedRecipe = repository.DeleteRecipe(recipeId); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Name} was deleted"; } } else { TempData["message"] = $"You are not allowed to delete!"; } return(RedirectToAction("DataPage")); }
public IActionResult Delete(int RecipeID) { System.Diagnostics.Debug.WriteLine("Delete Recipe", RecipeID); var query5 = from s in commentRepo.RecipeComments where s.RecipeID == RecipeID orderby s.RecipeID select s; foreach (RecipeComment s in query5) { commentRepo.DeleteRecipeComment(s.RecipeCommentId); } Recipe deletedRecipe = recipeRepo.DeleteRecipe(RecipeID); if (deletedRecipe != null) { TempData["message"] = $"{deletedRecipe.Name} was deleted"; } return(RedirectToAction("DataPage", "Home")); }
public ActionResult Delete(int id) { try { //Check to see if recipe exist and if not tell user it doesn't var recipeExist = _recipeRepository.DoesRecipeExist(id); if (!recipeExist) { return(BadRequest("Recipe does not Exist")); } _recipeRepository.DeleteRecipe(id); _log.Info($"Recipe with {id} was deleted successfully :)"); return(Ok("Recipe is deleted :)")); } catch (Exception e) { _log.Error($"Failed to delete recipe. {e}"); return(BadRequest($"Failed to delete recipe. {e}")); } }
public async Task <IActionResult> UpdateIngredient(Guid recipeId) { await _recipeRepository.DeleteRecipe(recipeId); return(Ok(recipeId)); }
public RecipeResponse DeleteRecipe(Guid id) { return(_recipeRepository.DeleteRecipe(id)); }
public ViewResult DeleteRecipe(string id) { Console.WriteLine("Delete Recipe ....... ID : [" + id + "]"); // Before this controller goes to RecipeLIst view, rlv model can toss to the view. rlv.Recipes = iRecipeRepo.Recipes; rlv.Categories = iCategoryRepo.Categories; rlv.ModalDetails = iModalDetailRepo.ModalDetails; rlv.RecipeModals = iRecipeModalRepo.RecipeModals; rlv.RecipeIngredients = iRecipeIngredientRepo.RecipeIngredients; rlv.IngredientDetails = iIngredientDetailRepo.IngredientDetails; rlv.RecipeReviewComments = iRecipeReviewCommentRepo.RecipeReviewComments; rlv.ReviewCommentDetails = iReviewCommentDetailRepo.ReviewCommentDetails; //Before the Neuavenue system is removed recipe, from bridge table //The system will has to indicate which ReviewComment belong to the recipe Id. // In order to remove IngredientStrings in IngredientDetail which belongs to IngredientId int recipeId = Convert.ToInt32(id); List <RecipeIngredient> recipeIngredients = rlv.RecipeIngredients.Where(ri => ri.RecipeId == recipeId).ToList <RecipeIngredient>(); foreach (RecipeIngredient recipeIngredient in recipeIngredients) { iRecipeIngredientRepo.DeleteRecipeIngredient(recipeIngredient); IngredientDetail ingredientDetail = rlv.IngredientDetails.First <IngredientDetail>( ind => ind.IngredientId == recipeIngredient.IngredientId); iIngredientDetailRepo.DeleteIngredientDetail(ingredientDetail); } //remove the data in RecipeModal which are the data (1, 2, 3 by recipeId) which has to be deleted. List <RecipeModal> recipeModals = rlv.RecipeModals.Where(rm => rm.RecipeId == recipeId).ToList <RecipeModal>(); foreach (RecipeModal recipeModal in recipeModals) { Console.WriteLine("ModalId in recipeModal: " + recipeModal.ModalId); Console.WriteLine("RecipeId in recipeModal: " + recipeModal.RecipeId); iRecipeModalRepo.DeleteRecipeModal(recipeModal); } //Remove the data in RecipeReviewComment and ReviewCommentDetail by recipeId which has to be deleted. List <RecipeReviewComment> recipeReviewComments = rlv.RecipeReviewComments.Where( rrc => rrc.RecipeId == recipeId).ToList <RecipeReviewComment>(); foreach (RecipeReviewComment recipeReviewComment in recipeReviewComments) { iRecipeReviewCommentRepo.DeleteRecipeReviewComment(recipeReviewComment); ReviewCommentDetail reviewCommentDetail = rlv.ReviewCommentDetails.First <ReviewCommentDetail>( rcd => rcd.ReviewCommentId == recipeReviewComment.ReviewCommentId); iReviewCommentDetailRepo.DeleteReviewCommentDetail(reviewCommentDetail); } //Remove Recipe by its RecipeId. Recipe DeleteRecipe = iRecipeRepo.Recipes.First <Recipe>(r => r.RecipeId.ToString() == id); iRecipeRepo.DeleteRecipe(DeleteRecipe); return(View("RecipeList", rlv)); }