예제 #1
0
        /// <summary>
        /// Uses a <see cref="GroupMemberService"/> to determine
        /// whether a given <see cref="User"/> is a member of this
        /// or of a nested <see cref="Group"/>.
        /// </summary>
        /// <param name="user">
        /// A <see cref="User"/> entity to check.
        /// </param>
        /// <param name="groupMemberService">
        /// The instance of <see cref="GroupMemberService"/>
        /// to use for checking nested group membership.
        /// </param>
        /// <returns>
        /// <c>true</c> if the given <paramref name="user"/>
        /// is a member of this group or of a nested group;
        /// otherwise, <c>false</c>.
        /// </returns>
        public bool IsMember(User user, GroupMemberService groupMemberService)
        {
            AssertionConcern.AssertArgumentNotNull(user, "User must not be null.");
            AssertionConcern.AssertArgumentEquals(this.TenantId, user.TenantId, "Wrong tenant for this group.");
            AssertionConcern.AssertArgumentTrue(user.IsEnabled, "User is not enabled.");

            bool isMember = this.GroupMembers.Contains(user.ToGroupMember());

            if (isMember)
            {
                isMember = groupMemberService.ConfirmUser(this, user);
            }
            else
            {
                isMember = groupMemberService.IsUserInNestedGroup(this, user);
            }

            return(isMember);
        }