-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMainMenu.cs
48 lines (42 loc) · 2.41 KB
/
MainMenu.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Linq;
using Orchard;
using Orchard.ContentManagement;
using Orchard.Core.Navigation.Models;
using Orchard.Localization;
using Orchard.UI.Navigation;
using Orchard.Core.Title.Models;
namespace PJS.Bootstrap {
public class MainMenu : IMenuProvider {
private readonly IContentManager _contentManager;
private readonly IOrchardServices _orchardServices;
public MainMenu(IContentManager contentManager, IOrchardServices orchardServices) {
_contentManager = contentManager;
_orchardServices = orchardServices;
}
public Localizer T { get; set; }
public void GetMenu(IContent menu, NavigationBuilder builder) {
if (menu.As<TitlePart>().Title == "Main Menu") {
var maxPosition = _contentManager
.Query<MenuPart, MenuPartRecord>()
.Where(x => x.MenuId == menu.Id)
.List()
.Select(x => Convert.ToInt32(decimal.Parse(x.MenuPosition)))
.Max();
var itemCount = maxPosition + 1;
if (_orchardServices.WorkContext.CurrentUser != null) {
builder.Add(T(_orchardServices.WorkContext.CurrentUser.UserName), itemCount.ToString(), item => item.Url("#").AddClass("menuUserName"));
builder.Add(T("Change Password"), itemCount.ToString() + ".1", item => item.Action("ChangePassword", "Account", new { area = "Orchard.Users" }));
builder.Add(T("Sign Out"), itemCount.ToString() + ".2", item => item.Action("LogOff", "Account", new { area = "Orchard.Users", ReturnUrl = _orchardServices.WorkContext.HttpContext.Request.RawUrl }));
if (_orchardServices.Authorizer.Authorize(Orchard.Security.StandardPermissions.AccessAdminPanel)) {
builder.Add(T("Dashboard"), itemCount.ToString() + ".3", item => item.Action("Index", "Admin", new { area = "Dashboard" }));
}
}
else {
builder.Add(T("Sign In"), itemCount.ToString(), item => item.Action("LogOn", "Account", new { area = "Orchard.Users", ReturnUrl = (_orchardServices.WorkContext.HttpContext.Request.QueryString["ReturnUrl"] ?? _orchardServices.WorkContext.HttpContext.Request.RawUrl) }));
}
}
}
public string MenuName { get { return "Main Menu"; } }
}
}