public bool IsInRole(string roleCode, string userCode) { string userrols = UserCache.GetItem(userCode, "UserRoles"); if (!string.IsNullOrEmpty(userrols)) { return(userrols.IndexOf("," + roleCode + ",") >= 0); } else { List <string> roles = userRepository.GetUserRoleCodes(userCode); UserCache.AddItem(userCode, "UserRoles", "," + string.Join(",", roles.ToArray()) + ","); return(roles.Contains(roleCode)); } }
/// <summary> /// 判断用户是否拥有某个权限 /// </summary> /// <param name="userUid">The user uid.</param> /// <param name="privilegeCode">The privilege code.</param> /// <returns> /// <c>true</c> if the specified user uid has right; otherwise, <c>false</c>. /// </returns> public bool HasRight(string userUid, string privilegeCode) { bool IsAdminRole = IsInRole(userUid, AppConfig.SuperAdminRoleCode); if (IsAdminRole) //如果是管理员角色 { return(true); } string hasright = UserCache.GetItem(userUid, "HasRight_" + privilegeCode); if (hasright == null) { bool hr = userRepository.CheckUserRight(userUid, privilegeCode); UserCache.AddItem("HasRight_" + privilegeCode, hr ? "true" : "false"); return(hr); } else { return(hasright.ToLower() == "true"); } }
private void setValidateItemsCache(List <ValidationItemVM> items, DateTime period) { var key = getValidationItemsCacheKey(period); UserCache.AddItem(key, items); }