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