Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 65 posts 209 karma points
    May 02, 2014 @ 15:00
    Dan
    0

    Get only members in choosen membergroubs

    Sorry but this will be a little long.. I want to show members from picked groups, so If I have following members:

    member 1 with groups: group 1, group 2, group 3
    member 2 with groups: group 1, group 2
    member 3 with groups: group 1

    So if I only choose group 1 I will get all members, but If i choose group 1, group 2, group 3 I will only get member 1.

    So first ill get all members In all the groups like this

    List<List<IMember>> listWithMemberInGroupsList = new List<List<IMember>>();
    var memberService = ApplicationContext.Current.Services.MemberService;
    foreach (string group in memberGroups)
    {
        List<IMember> membersInGroup = memberService.GetMembersByGroup(group).ToList();
        listWithMemberInGroupsList.Add(membersInGroup);
    }
    

    Then I got a list with list of members then I have to find the members which is in all the lists, This I made with the intersection metod on a list.

    public List<IMember> getMembersToshow(List<List<IMember>> listWithMemberInGroupsList , int i = 0)
    {
        List<IMember> MembersToAddToPage = new List<IMember>();
        while (i < listWithMemberInGroupsList.Count)
        {
            int compareListInt = i + 1;
            if (i == 0)
            {
                MembersToAddToPage = groupWithMemberList[i].Intersect(listWithMemberInGroupsList [compareListInt]).ToList();    
            }
            else
            {
                MembersToAddToPage = compareNextListWithLastResult(MembersToAddToPage, groupWithMemberList[compareListInt]);
            }
    
            i = i + 2; 
        }
        return MembersToAddToPage;
    }  
    
    
    public List<IMember> compareNextListWithLastResult(List<IMember> resultList, List<IMember> compareList)
    {
        List<IMember> MembersToAddToPage = new List<IMember>();
        MembersToAddToPage = resultList.Intersect(compareList).ToList();
    
        return MembersToAddToPage;
    } 
    

    Now I cant find a way to make this faster because unfortunately it's a little slow by now.

Please Sign in or register to post replies

Write your reply to:

Draft