FilterGroups() private method

Filters the GlymaSPSecurityGroup dictionary so that groups only return for the highest permission level they've been granted.
private FilterGroups ( ) : IList>.IDictionary
return IList>.IDictionary
        internal GetAllSecurityGroupsResponse GetAllGlymaSecurityGroups()
        {
            GetAllSecurityGroupsResponse result = new GetAllSecurityGroupsResponse() { HasError = false };

            IList<string> permissionLevelNames = new List<string>();
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaProjectManager));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapManager));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthor));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReader));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReaderOld));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthorOld));

            Dictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>> results = new Dictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>>();
            foreach (string permissionLevelName in permissionLevelNames)
            {
                GlymaPermissionLevel permissionLevel = GlymaPermissionLevelHelper.GetPermissionLevelByName(permissionLevelName);
                GetSecurityGroupsResponse response = GetSecurityGroups(permissionLevel);
                if (!response.HasError)
                {
                    IList<GlymaSecurityGroup> groups = response.Result;
                    if (results.ContainsKey(permissionLevel))
                    {
                        foreach (GlymaSecurityGroup group in groups)
                        {
                            if (!results[permissionLevel].Contains(group))
                            {
                                results[permissionLevel].Add(group);
                            }
                        }
                    }
                    else
                    {
                        results.Add(permissionLevel, groups);
                    }
                }
                else
                {
                    result.HasError = true;
                    result.ErrorMessage = response.ErrorMessage;
                    break; //an error occurred so stop at this point
                }
            }
            if (!result.HasError)
            {
                GlymaSecurityGroupCollection groups = new GlymaSecurityGroupCollection(this, results);
                IDictionary<GlymaPermissionLevel, IList<GlymaSecurityGroup>> filteredGroups = groups.FilterGroups();
                result.Result = filteredGroups;
            }

            return result;
        }
        internal GetAllSecurityGroupsResponse GetAllGlymaSecurityGroups()
        {
            GetAllSecurityGroupsResponse result = new GetAllSecurityGroupsResponse()
            {
                HasError = false
            };

            IList <string> permissionLevelNames = new List <string>();

            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaProjectManager));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapManager));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthor));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReader));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapReaderOld));
            permissionLevelNames.Add(GlymaPermissionLevelHelper.GetPermissionLevelName(GlymaPermissionLevel.GlymaMapAuthorOld));

            Dictionary <GlymaPermissionLevel, IList <GlymaSecurityGroup> > results = new Dictionary <GlymaPermissionLevel, IList <GlymaSecurityGroup> >();

            foreach (string permissionLevelName in permissionLevelNames)
            {
                GlymaPermissionLevel      permissionLevel = GlymaPermissionLevelHelper.GetPermissionLevelByName(permissionLevelName);
                GetSecurityGroupsResponse response        = GetSecurityGroups(permissionLevel);
                if (!response.HasError)
                {
                    IList <GlymaSecurityGroup> groups = response.Result;
                    if (results.ContainsKey(permissionLevel))
                    {
                        foreach (GlymaSecurityGroup group in groups)
                        {
                            if (!results[permissionLevel].Contains(group))
                            {
                                results[permissionLevel].Add(group);
                            }
                        }
                    }
                    else
                    {
                        results.Add(permissionLevel, groups);
                    }
                }
                else
                {
                    result.HasError     = true;
                    result.ErrorMessage = response.ErrorMessage;
                    break; //an error occurred so stop at this point
                }
            }
            if (!result.HasError)
            {
                GlymaSecurityGroupCollection groups = new GlymaSecurityGroupCollection(this, results);
                IDictionary <GlymaPermissionLevel, IList <GlymaSecurityGroup> > filteredGroups = groups.FilterGroups();
                result.Result = filteredGroups;
            }

            return(result);
        }