/// <summary> /// Sets members of the group. /// </summary> /// <param name="newMembers">List of group members.</param> public override async Task SetGroupMembersAsync(IList <IPrincipal> newMembers) { PrincipalCollection members = groupPrincipal.Members; IEnumerable <Principal> toDelete = members.Where(m => !newMembers.Where(nm => ((PrincipalBase)nm).Principal.Sid.Value == m.Sid.Value).Any()).ToList(); foreach (Principal p in toDelete) { groupPrincipal.Members.Remove(p); } IEnumerable <IPrincipal> toAdd = newMembers.Where(nm => !members.Where(m => m.Sid.Value == ((PrincipalBase)nm).Principal.Sid.Value).Any()).ToList(); foreach (PrincipalBase p in toAdd) { groupPrincipal.Members.Add(p.Principal); } Context.PrincipalOperation(groupPrincipal.Save); }
public void Add <T>(T value) { if (value.GetType() == typeof(D)) { var dependantKey = DependantKeyInfo.GetValue(value); var principals = PrincipalCollection.Where(p => this.PrincipalForeignKeyInfo.GetValue(p).Equals(dependantKey)) .ToList(); foreach (var principal in principals) { PrincipalRelationInfo.SetValue(principal, value); } } }