Inheritance: ValueObject
        public bool IsMemberGroup(Group group, GroupMember memberGroup)
        {
            bool isMember = false;

            foreach (GroupMember member in group.GroupMembers)
            {
                if (member.IsGroup())
                {
                    if (memberGroup.Equals(member))
                    {
                        isMember = true;
                    }
                    else
                    {
                        Group nestedGroup =
                            this.GroupRepository.GroupNamed(member.TenantId, member.Name);

                        if (nestedGroup != null)
                        {
                            isMember = this.IsMemberGroup(nestedGroup, memberGroup);
                        }
                    }
                }

                if (isMember)
                {
                    break;
                }
            }

            return isMember;
        }
        public bool IsMemberGroup(Group group, GroupMember memberGroup)
        {
            var isMember = false;

            foreach (var member in group.GroupMembers.Where(x => x.IsGroup))
            {
                if (memberGroup.Equals(member))
                {
                    isMember = true;
                }
                else
                {
                    var nestedGroup = this.groupRepository.GroupNamed(member.TenantId, member.Name);
                    if (nestedGroup != null)
                    {
                        isMember = IsMemberGroup(nestedGroup, memberGroup);
                    }
                }

                if (isMember)
                {
                    break;
                }
            }

            return isMember;
        }
		private bool IsMemberGroup(Group group, GroupMember memberGroup, int recursionCount)
		{
			if (recursionCount > MaxGroupNestingRecursion)
			{
				throw new InvalidOperationException("The maximum depth of group nesting has been exceeded, stopping recursive function.");
			}

			bool isMember = false;
			foreach (GroupMember member in group.GroupMembers.Where(x => x.IsGroup))
			{
				if (memberGroup.Equals(member))
				{
					isMember = true;
				}
				else
				{
					Group nestedGroup = this.groupRepository.GroupNamed(member.TenantId, member.Name);
					if (nestedGroup != null)
					{
						int nextRecursionCount = (recursionCount + 1);

						isMember = this.IsMemberGroup(nestedGroup, memberGroup, nextRecursionCount);
					}
				}

				if (isMember)
				{
					break;
				}
			}

			return isMember;
		}
		/// <summary>
		/// Recursive function which determines whether
		/// a <see cref="Group"/> is a member of a group
		/// or of a descendant group.
		/// </summary>
		/// <param name="group">
		/// An instance of <see cref="Group"/> to check for
		/// the presence of <paramref name="memberGroup"/>
		/// among its members or descendants.
		/// </param>
		/// <param name="memberGroup">
		/// Another group which may potentially be added to the
		/// members of <paramref name="group"/> if it's allowed.
		/// </param>
		/// <returns>
		/// <c>true</c> if the given <paramref name="memberGroup"/>
		/// is a member of the given <paramref name="group"/> or of
		/// a descendant group; otherwise, <c>false</c>.
		/// </returns>
		public bool IsMemberGroup(Group group, GroupMember memberGroup)
		{
			return this.IsMemberGroup(group, memberGroup, 0);
		}
Beispiel #5
0
        internal GroupMember ToGroupMember()
        {
            GroupMember groupMember =
                new GroupMember(
                        this.TenantId,
                        this.Name,
                        GroupMemberType.Group);

            return groupMember;
        }