// GET: Recipe/Delete/5 public ActionResult Delete(string id) { var recipe = this.manager.Find(Guid.Parse(id)); int brewsCount = this.manager.GetBrewsCount(Guid.Parse(id)); var model = new RecipeDeleteViewModel { Name = recipe.Name, BrewsCount = brewsCount }; return(View(model)); }
public ActionResult Delete(int id) { using (var context = new ApplicationDbContext()) { var recipeService = new RecipeService(context, HttpContext); var recipe = recipeService.GetRecipe(id); if (recipe == null) { return(HttpNotFound()); } var viewModel = new RecipeDeleteViewModel(recipe); return(View(viewModel)); } }
internal void Delete(RecipeDeleteViewModel model) { var userService = new UserService(_context, _httpContext); var userCleranceLevel = userService.GetCurrentUserCleranceLevel(); if (userCleranceLevel.Level < model.ClassificationLevel) { return; } var recipe = new Recipe { Id = model.Id }; _context.Recipes.Attach(recipe); _context.Entry(recipe).State = EntityState.Deleted; }
public ActionResult Delete(RecipeDeleteViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { using (var context = new ApplicationDbContext()) { var recipeService = new RecipeService(context, HttpContext); recipeService.Delete(model); context.SaveChanges(); return(RedirectToAction("Index")); } } catch { return(View(model)); } }
public async Task <IActionResult> Delete(RecipeDeleteViewModel viewModel) { await this.recipesService.DeleteAsync(viewModel.Id); return(this.RedirectToAction(nameof(Web.Controllers.RecipesController.All), new { area = string.Empty })); }