public IHttpActionResult Delete(int id) { Recipes recipe = db.Recipes.Find(id); db.Recipes.Remove(recipe); db.SaveChanges(); string path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "Upload\\Images", recipe.PictureUrl); File.Delete(path); List<Comments> comments = new CommentManager().GetRecipeCommentsList(id); foreach (Comments comment in comments) { db.Comments.Remove(comment); } db.SaveChanges(); return Ok(); }
public ActionResult Search(CategoriesListData model, int pageNumber = 1) { model.AllCategory = new CategoryManager().GetAllCategory(); Recipes recipe = db.Recipes.Find(model.RecipesDB.ID); db.Recipes.Remove(recipe); try { System.IO.File.Delete(Path.Combine(Server.MapPath("~"), "Upload\\Images", recipe.PictureUrl)); } catch { } List<Comments> comments = new CommentManager().GetRecipeCommentsList(model.RecipesDB.ID); foreach (Comments comment in comments) { db.Comments.Remove(comment); } db.SaveChanges(); model.Recipes = new RecipeManager().GetAllRecipeHeaderData(pageNumber); return View(model); }
public ActionResult Details(CategoriesListData model, int pageNumber = 1) { CategoryManager manager = new CategoryManager(); model.AllCategory = manager.GetAllCategory(); Recipes recipe = db.Recipes.Find(model.RecipesDB.ID); db.Recipes.Remove(recipe); System.IO.File.Delete(Path.Combine(Server.MapPath("~"), "Upload\\Images", recipe.PictureUrl)); db.SaveChanges(); List<Comments> comments = new CommentManager().GetRecipeCommentsList(model.RecipesDB.ID); foreach (Comments comment in comments) { db.Comments.Remove(comment); } db.SaveChanges(); Categories category = db.Categories.Find(model.SelectedCategory.ID); model.Recipes = manager.GetRecipesInCategory(category.FriendlyUrl, pageNumber); model.SelectedCategory = model.AllCategory.FirstOrDefault(c => c.FriendlyUrl == category.FriendlyUrl); return View(model); }