public IActionResult GetGroupPower(int groupId) { AuthorizationRepository repository = new AuthorizationRepository(); List <Models.UserGroupPowerModel> result = repository.GetPowerData(groupId); return(Json(result)); }
/// <summary> /// 根据用户组获取权限 /// </summary> /// <param name="groupID"></param> /// <returns></returns> private static List <Models.UserGroupPowerModel> GetPowerData(int groupID) { List <Models.UserGroupPowerModel> Result = null; ICacheService CacheService = ServiceContext.GetService <ICacheService>(); string PowerCache = CacheService.Get(string.Format("UserGroupPowerCache{0}", groupID)); if (string.IsNullOrEmpty(PowerCache)) { AuthorizationRepository repository = new AuthorizationRepository(); Result = repository.GetPowerData(groupID); PowerCache = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Result))); //写入缓存 CacheService.Add(string.Format("UserGroupPowerCache{0}", groupID), PowerCache); } else { PowerCache = Encoding.UTF8.GetString(Convert.FromBase64String(PowerCache.Replace("\"", ""))); //从缓存中获取 Result = JsonConvert.DeserializeObject <List <Models.UserGroupPowerModel> >(PowerCache); } return(Result); }