Beispiel #1
0
        /// <summary>Returns true if a user is in the role</summary>
        /// <param name="user">用户实体</param>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public Task <bool> IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException("roleName");
            }


            return(TaskHelper.RunTask(() =>
            {
                var userId = user.Id;
                return _objectStorage.Any <UserRole>(p => p.UserId == userId && p.RoleName == roleName);
            }));
        }