2019-06-30 23:15:43 +08:00
|
|
|
|
using Bootstrap.Security.DataAccess;
|
|
|
|
|
using Longbow.Cache;
|
2019-02-24 17:27:41 +08:00
|
|
|
|
using Longbow.Data;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-02-24 17:27:41 +08:00
|
|
|
|
public static class AppHelper
|
|
|
|
|
{
|
2019-06-24 10:42:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-02-24 17:27:41 +08:00
|
|
|
|
public const string RetrieveAppsByRoleIdDataKey = "AppHelper-RetrieveAppsByRoleId";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据角色ID指派应用程序
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static IEnumerable<App> RetrievesByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveAppsByRoleIdDataKey, roleId), key => DbContextManager.Create<App>().RetrievesByRoleId(roleId), RetrieveAppsByRoleIdDataKey);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据角色ID以及选定的App ID,保到角色应用表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
/// <param name="appIds"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool SaveByRoleId(string roleId, IEnumerable<string> appIds)
|
|
|
|
|
{
|
|
|
|
|
var ret = DbContextManager.Create<App>().SaveByRoleId(roleId, appIds);
|
|
|
|
|
if (ret) CacheCleanUtility.ClearCache(appIds: appIds, roleIds: new List<string>() { roleId });
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-02-25 14:41:04 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据指定用户名获得授权应用程序集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userName"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-06-30 23:15:43 +08:00
|
|
|
|
public static IEnumerable<string> RetrievesByUserName(string userName) => CacheManager.GetOrAdd($"{DbHelper.RetrieveAppsByUserNameDataKey}-{userName}", key => DbContextManager.Create<App>().RetrievesByUserName(userName), DbHelper.RetrieveAppsByUserNameDataKey);
|
2019-02-24 17:27:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|