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)); }
public ActionResult Delete(int id) { var categoriesDelete = new CategoriesDeleteViewModel(); categoriesDelete.Category = _context.FindId(id); if (categoriesDelete.Category == null) { return(NotFound()); } return(PartialView(categoriesDelete)); }
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")); }
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); }