Example #1
0
        public bool CheckPermission(long userId, string permission, bool checkFather = false)
        {
            var arr  = permission.Split('|');
            var path = arr[0];
            var desc = arr[0];

            if (arr.Length > 1)
            {
                desc = arr[1];
            }
            var isPermission = _permissionResponsitory.Where(p => p.Path == path).Any();

            if (!isPermission)
            {
                _permissionResponsitory.Insert(new Permission {
                    Path = path, Description = desc
                });
                return(false);
            }
            //TODO 先从缓存读取权限信息
            var roles = _userRoleResponsitory.Where(p => p.UserId == userId).ToList();

            if (!roles.Any())
            {
                return(false);
            }
            var roleIds = roles.Select(p => p.Id).ToList();

            Debug.WriteLine("验证权限:" + path);
            var isCheck = _rolePermissionResponsitory.Where(p => p.Permission.Path == path && roleIds.Contains(p.RoleId)).Any();

            if (isCheck && checkFather)
            {
                var index = path.LastIndexOf('.');
                if (index != -1)
                {
                    path = path.Substring(0, index);
                    Debug.WriteLine("验证权限:" + path);
                    _rolePermissionResponsitory.Where(p => p.Permission.Path == path && roleIds.Contains(p.RoleId)).Any();
                }
            }
            return(isCheck);
        }
Example #2
0
        public IEnumerable <RolePermission> GetAll(int pageIndex, int pageSize)
        {
            var result = _responsitory.Where(p => true).OrderBy(p => p.Id).Skip((pageIndex - 1) * pageSize).Limit(pageSize).ToList();

            return(result);
        }