Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether the identity is a member of the accounts collection,
 /// either directly, or indirectly through a group or a role membership
 /// </summary>
 /// <param name="accounts">The accounts.</param>
 /// <param name="identity">The identity.</param>
 /// <returns>
 /// 	<c>true</c> if the identity is a member of the collection ; otherwise, <c>false</c>.
 /// </returns>
 public static bool ContainsOrMemberOf(this ICollection<IIdentity> accounts,IIdentity identity)
 {
     if (accounts.Count(a => a.GetMappedId() == identity.GetMappedId()) > 0)
         return true;
     IEnumerable<IIdentity> groups =identity.MemberOf();
     IEnumerable<IIdentity> roles = identity.InRoles();
     return
         groups.Select(a=>a.GetMappedId()).Any(accounts.Select(a=>a.GetMappedId()).Contains) ||
         roles.Select(a => a.GetMappedId()).Any(accounts.Select(a => a.GetMappedId()).Contains);
 }