#19135: Fixing menu item hirerachies deletion

Work Item: 19135

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-10-16 17:43:36 -07:00
parent 4386060607
commit 5223f74571

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
@@ -117,13 +118,22 @@ namespace Orchard.Core.Navigation.Controllers {
if (menuPart != null) {
menuId = menuPart.Menu.Id;
// if the menu item is a concrete content item, don't delete it, just unreference the menu
if (!menuPart.ContentItem.TypeDefinition.Settings.ContainsKey("Stereotype") || menuPart.ContentItem.TypeDefinition.Settings["Stereotype"] != "MenuItem") {
menuPart.Menu = null;
}
else {
_menuService.Delete(menuPart);
// get all sub-menu items from the same menu
var menuItems = _menuService.GetMenuParts(menuPart.Menu.Id)
.Where(x => x.MenuPosition.StartsWith(menuPart.MenuPosition + "."))
.Select(x => x.As<MenuPart>())
.ToList();
foreach (var menuItem in menuItems.Concat(new [] {menuPart})) {
// if the menu item is a concrete content item, don't delete it, just unreference the menu
if (!menuPart.ContentItem.TypeDefinition.Settings.ContainsKey("Stereotype") || menuPart.ContentItem.TypeDefinition.Settings["Stereotype"] != "MenuItem") {
menuPart.Menu = null;
}
else {
_menuService.Delete(menuItem);
}
}
}
return RedirectToAction("Index", new { menuId });