2010-02-15 14:01:13 -08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2010-02-14 23:17:26 -08:00
|
|
|
|
using Orchard.ContentManagement;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
using Orchard.Core.Navigation.Drivers;
|
2010-02-14 23:17:26 -08:00
|
|
|
|
using Orchard.Core.Navigation.Models;
|
2010-02-10 13:23:11 -08:00
|
|
|
|
using Orchard.Core.Navigation.ViewModels;
|
|
|
|
|
using Orchard.Localization;
|
2010-02-12 13:08:41 -08:00
|
|
|
|
using Orchard.UI.Navigation;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
using Orchard.Utility;
|
2010-02-14 23:17:26 -08:00
|
|
|
|
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
|
2010-02-10 13:23:11 -08:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Navigation.Controllers {
|
|
|
|
|
[ValidateInput(false)]
|
2010-02-14 23:17:26 -08:00
|
|
|
|
public class AdminController : Controller, IUpdateModel {
|
2010-02-12 13:08:41 -08:00
|
|
|
|
private readonly IOrchardServices _services;
|
|
|
|
|
private readonly INavigationManager _navigationManager;
|
2010-02-10 13:23:11 -08:00
|
|
|
|
|
2010-02-12 13:08:41 -08:00
|
|
|
|
public AdminController(IOrchardServices services, INavigationManager navigationManager) {
|
|
|
|
|
_services = services;
|
|
|
|
|
_navigationManager = navigationManager;
|
2010-02-10 13:23:11 -08:00
|
|
|
|
T = NullLocalizer.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-14 23:17:26 -08:00
|
|
|
|
private Localizer T { get; set; }
|
2010-02-10 13:23:11 -08:00
|
|
|
|
|
2010-02-15 16:49:09 -08:00
|
|
|
|
public ActionResult Index(NavigationManagementViewModel model) {
|
2010-02-14 23:17:26 -08:00
|
|
|
|
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Not allowed to manage the main menu")))
|
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
2010-02-15 16:49:09 -08:00
|
|
|
|
if (model == null)
|
|
|
|
|
model = new NavigationManagementViewModel();
|
2010-02-12 13:08:41 -08:00
|
|
|
|
|
2010-02-15 16:49:09 -08:00
|
|
|
|
if (model.Menu == null || model.Menu.Count() < 1)
|
|
|
|
|
model.Menu = _navigationManager.BuildMenu("main");
|
|
|
|
|
|
|
|
|
|
return View("Index", model);
|
2010-02-10 13:23:11 -08:00
|
|
|
|
}
|
2010-02-14 23:17:26 -08:00
|
|
|
|
|
|
|
|
|
[HttpPost, ActionName("Index")]
|
|
|
|
|
public ActionResult IndexPOST() {
|
|
|
|
|
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
|
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Create(CreateMenuItemViewModel model) {
|
|
|
|
|
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
|
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
|
|
|
|
var menuItem = _services.ContentManager.New<MenuItem>(MenuItemDriver.ContentType.Name);
|
|
|
|
|
model.MenuItem = _services.ContentManager.UpdateEditorModel(menuItem, this);
|
|
|
|
|
|
|
|
|
|
if (!ModelState.IsValid) {
|
|
|
|
|
_services.TransactionManager.Cancel();
|
2010-02-15 16:49:09 -08:00
|
|
|
|
return Index(new NavigationManagementViewModel {NewMenuItem = model});
|
2010-02-14 23:17:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 14:01:13 -08:00
|
|
|
|
if (string.IsNullOrEmpty(menuItem.As<MenuPart>().MenuPosition))
|
|
|
|
|
menuItem.As<MenuPart>().MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main"));
|
2010-02-14 23:17:26 -08:00
|
|
|
|
menuItem.As<MenuPart>().OnMainMenu = true;
|
2010-02-15 14:01:13 -08:00
|
|
|
|
|
2010-02-14 23:17:26 -08:00
|
|
|
|
_services.ContentManager.Create(model.MenuItem.Item.ContentItem);
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[ValidateAntiForgeryTokenOrchard, ActionName("Delete")]
|
|
|
|
|
[HttpPost, ActionName("Delete")]
|
|
|
|
|
public ActionResult DeletePOST(int menuItemId)
|
|
|
|
|
{
|
|
|
|
|
if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
|
|
|
|
|
return new HttpUnauthorizedResult();
|
|
|
|
|
|
|
|
|
|
//todo -> delete
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
|
|
|
|
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
|
|
|
|
|
ModelState.AddModelError(key, errorMessage.ToString());
|
|
|
|
|
}
|
2010-02-10 13:23:11 -08:00
|
|
|
|
}
|
|
|
|
|
}
|