mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using System.Linq;
|
|
using Orchard.Blogs.Services;
|
|
using Orchard.UI.Navigation;
|
|
|
|
namespace Orchard.Blogs {
|
|
public class AdminMenu : INavigationProvider {
|
|
private readonly IBlogService _blogService;
|
|
|
|
public AdminMenu(IBlogService blogService) {
|
|
_blogService = blogService;
|
|
}
|
|
|
|
public string MenuName { get { return "admin"; } }
|
|
|
|
public void GetNavigation(NavigationBuilder builder) {
|
|
builder.Add("Blogs", "2", BuildMenu);
|
|
}
|
|
|
|
private void BuildMenu(NavigationItemBuilder menu) {
|
|
var blogs = _blogService.Get();
|
|
var blogCount = blogs.Count();
|
|
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;
|
|
|
|
if (blogCount > 0 && singleBlog == null)
|
|
menu.Add("Manage Blogs", "1.0",
|
|
item =>
|
|
item.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.MetaListBlogs));
|
|
else if (singleBlog != null)
|
|
menu.Add("Manage Blog", "1.0",
|
|
item =>
|
|
item.Action("Item", "BlogAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.MetaListBlogs));
|
|
|
|
menu.Add("Add New Blog", "1.1",
|
|
item =>
|
|
item.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.ManageBlogs));
|
|
|
|
if (singleBlog != null)
|
|
menu.Add("Add New Post", "1.2",
|
|
item =>
|
|
item.Action("Create", "BlogPostAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.PublishBlogPost));
|
|
}
|
|
}
|
|
} |