public async Task <VotedLdapGroup> AddMembers(VotedLdapGroup group, string startEvent, string endEvent, DateTime startDate, List <string> newMembers, string changedBy, CancellationToken cancellationToken) { await newMembers.ForEachAsync(async m => { var id = $"{m}_{DateTime.Now:yyyyMMddHHmmss}"; var voteEntry = new VoteEntry { Id = id, Dn = $"cn={id},{group.Dn}", MemberUid = m, Active = true, VoteStartEvent = startEvent, VoteEndEvent = endEvent, VoteStartDate = startDate, }; await this._connection.Add(voteEntry, changedBy, cancellationToken); group.ActiveVoteEntries.Add(voteEntry); group.MemberIds.Add(m); }); await this._connection.Update(group, changedBy, cancellationToken); return(group); }
public async Task <ICollection <LdapMember> > ListVotedGroupMembers(VotedLdapGroup group, CancellationToken cancellationToken = default) { List <string> memberIds = new List <string>(); group.ActiveVoteEntries.ToList().ForEach(m => memberIds.Add(m.MemberUid)); group.InactiveVoteEntries.ToList().ForEach(m => memberIds.Add(m.MemberUid)); // TODO: I'm pretty sure it is faster to load all members and filter them with LINQ in comparision to individual searches for each member id. ICollection <LdapMember> allMembers = await this._connection.Search <LdapMember>(this._config.MemberDn, null, LdapObjectTypes.Member, LdapConnection.SCOPE_ONE, LdapMember.LoadProperties, cancellationToken); return(allMembers.Where(m => memberIds.Contains(m.Id)).ToList()); }
public async Task <IActionResult> Create([FromBody] VotedLdapGroup group, CancellationToken cancellationToken) { try { if (!this.GetUserLgsDivisions().Contains(group.DivisionId)) { return(this.Unauthorized()); } var newGroup = await this._manager.Create(group, nameof(VotedGroupController) + nameof(this.Create), cancellationToken); return(this.Ok(newGroup)); } catch (Exception ex) { this._logger.LogError(ex, nameof(VotedGroupController) + nameof(this.Create)); return(this.Error(this._env, ex)); } }
public async Task <VotedLdapGroup> RemoveMembers(VotedLdapGroup group, string endEvent, DateTime endDate, List <VoteEntry> removedMembers, string changedBy, CancellationToken cancellationToken = default) { await removedMembers.ForEachAsync(async m => { m = await this._connection.Read <VoteEntry>(m.Dn, cancellationToken); m.VoteEndDate = endDate; m.VoteEndEvent = endEvent; m.Active = false; await this._connection.Update(m, changedBy, cancellationToken); group.MemberIds.Remove(m.MemberUid); group.ActiveVoteEntries.Remove(group.ActiveVoteEntries.First(ve => ve.Dn == m.Dn)); group.InactiveVoteEntries.Add(m); }); await this._connection.Update(group, changedBy, cancellationToken); return(group); }
public async Task <VotedLdapGroup> Create(VotedLdapGroup group, string changedBy, CancellationToken cancellationToken = default) { return(await this._connection.Add(group, changedBy, cancellationToken)); }