Esempio n. 1
0
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var model = new CategoriesDeleteViewModel();

            model.Categories = new List <CategoryDeleteViewModel>();

            foreach (int id in ids)
            {
                Category category = categoryService.Find(id);
                if (category == null)
                {
                    continue;
                }

                model.Categories.Add(new CategoryDeleteViewModel
                {
                    Id            = category.Id,
                    Name          = category.Name,
                    ProductsCount = categoryService.GetProductsCount(id, true)
                });
            }
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Delete(int id)
        {
            var categoriesDelete = new CategoriesDeleteViewModel();

            categoriesDelete.Category = _context.FindId(id);
            if (categoriesDelete.Category == null)
            {
                return(NotFound());
            }
            return(PartialView(categoriesDelete));
        }
Esempio n. 3
0
        public IActionResult DeleteConfirm(int id)
        {
            var categoriesDelete = new CategoriesDeleteViewModel();

            categoriesDelete.Category = _context.FindId(id);
            if (categoriesDelete.Category.inverseCategoryChildrenNavigation.Length != 0)
            {
                return(BadRequest("Невозможно удалить! У этой категории есть дочерние категории!!!"));
            }
            try
            {
                _context.Delete(id);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok("Ok"));
        }
Esempio n. 4
0
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var model = new CategoriesDeleteViewModel();
            model.Categories = new List<CategoryDeleteViewModel>();

            foreach (int id in ids)
            {
                Category category = categoryService.Find(id);
                if (category == null) continue;

                model.Categories.Add(new CategoryDeleteViewModel
                {
                    Id = category.Id,
                    Name = category.Name,
                    ProductsCount = categoryService.GetProductsCount(id, true)
                });
            }
            return View(model);
        }