BootstrapAdmin/Bootstrap.Client.DataAccess/MenuHelper.cs

41 lines
1.5 KiB
C#
Raw Normal View History

2018-10-19 23:09:52 +08:00
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow.Cache;
using Longbow.Configuration;
2018-10-19 23:09:52 +08:00
using System.Collections.Generic;
using System.Linq;
2018-10-19 23:09:52 +08:00
namespace Bootstrap.Client.DataAccess
{
/// <summary>
///
/// </summary>
public static class MenuHelper
{
/// <summary>
///
/// </summary>
public const string RetrieveMenusAll = "BootstrapMenu-RetrieveMenus";
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="activeUrl"></param>
/// <returns></returns>
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string userName, string activeUrl)
{
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0 && m.ApplicationCode == ConfigurationManager.AppSettings["AppId"]);
DbHelper.ActiveMenu(null, menus, activeUrl);
2018-10-30 13:07:29 +08:00
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
return root;
}
/// <summary>
/// 通过用户获得所有菜单
/// </summary>
/// <param name="userName"></param>
2018-10-19 23:09:52 +08:00
/// <returns></returns>
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbHelper.RetrieveAllMenus(userName), RetrieveMenusAll);
2018-10-19 23:09:52 +08:00
}
}