mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using System.Linq;
|
|
using Orchard.Blogs.Services;
|
|
using Orchard.Localization;
|
|
using Orchard.UI.Navigation;
|
|
|
|
namespace Orchard.Blogs {
|
|
public class AdminMenu : INavigationProvider {
|
|
private readonly IBlogService _blogService;
|
|
|
|
public AdminMenu(IBlogService blogService) {
|
|
_blogService = blogService;
|
|
}
|
|
|
|
public Localizer T { get; set; }
|
|
|
|
public string MenuName { get { return "admin"; } }
|
|
|
|
public void GetNavigation(NavigationBuilder builder) {
|
|
builder.Add(T("Blogs"), "1", 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(T("Manage Blogs"), "1.0",
|
|
item =>
|
|
item.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.MetaListBlogs));
|
|
else if (singleBlog != null)
|
|
menu.Add(T("Manage Blog"), "1.0",
|
|
item =>
|
|
item.Action("Item", "BlogAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.MetaListBlogs));
|
|
|
|
if ( singleBlog != null )
|
|
menu.Add(T("Create New Post"), "1.1",
|
|
item =>
|
|
item.Action("Create", "BlogPostAdmin", new { area = "Orchard.Blogs", blogSlug = singleBlog.Slug }).Permission(Permissions.PublishBlogPost));
|
|
|
|
menu.Add(T("Create New Blog"), "1.2",
|
|
item =>
|
|
item.Action("Create", "BlogAdmin", new { area = "Orchard.Blogs" }).Permission(Permissions.ManageBlogs));
|
|
|
|
}
|
|
}
|
|
} |