//========================================================== //========================================================== // GET: AdminPanel/Categories/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ShopCategory shopCategory = db.ShopCategories.Find(id); if (shopCategory == null) { return(HttpNotFound()); } // создание модели представления ViewCategoryDelete category = new ViewCategoryDelete { Id = shopCategory.Id, Name = shopCategory.Name, Alias = shopCategory.Alias, Description = shopCategory.Description, DeleteAll = false }; if (shopCategory.ParentId != null) { category.Parent = db.ShopCategories.Find(shopCategory.ParentId).Name; } // подсчет подкатегорий category.CountChildCategories = ChildCategoriesCount(shopCategory.Id); // подсчет товаров category.CountProducts = 0; return(View(category)); }
public ActionResult DeleteConfirmed(ViewCategoryDelete model) { ShopCategory shopCategory = db.ShopCategories.Find(model.Id); if (model.DeleteAll) { DeleteChileCategories(shopCategory); db.ShopCategories.Remove(shopCategory); db.SaveChanges(); } else { ClearParent(shopCategory.Id); db.ShopCategories.Remove(shopCategory); db.SaveChanges(); } return(RedirectToAction("Index")); }