Exemplo n.º 1
0
        // 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));
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
        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 }));
        }