Пример #1
0
        private void ctrl_AddToGroup_Click(object sender, EventArgs e)
        {
            List <JarsResourceGroup> AllGrps = Context.ServiceClient.Get(new FindResourceGroups()
            {
                IsActive = true
            }).Groups.ConvertAll(gcConditions => gcConditions.ConvertTo <JarsResourceGroup>());
            IList <SearchEntity <int> > existingGroups  = ((IList <JarsResourceGroup>)groupsBindingSource.List).GenerateSearchEntities(x => x.Name, x => x.Id, true);
            IList <SearchEntity <int> > allSearchGroups = AllGrps.GenerateSearchEntities(x => x.Name, x => x.Id, false);

            IList <SearchEntity <int> > returnList = SelectEntitiesForm.ShowForm(existingGroups, allSearchGroups, "Select Groups");
            //convert the return list to the entities.
            IList <JarsResourceGroup> newList = new List <JarsResourceGroup>();

            foreach (var sEnt in returnList)
            {
                JarsResourceGroup opG = AllGrps.FirstOrDefault(op => op.Id.ToString() == sEnt.ValueId.ToString());
                if (opG != null)
                {
                    newList.Add(opG);
                }
            }
            (defaultBindingSource.Current as JarsResource).Groups.Clear();

            //add the new group, if there were any
            foreach (var grp in newList)
            {
                if ((defaultBindingSource.Current as JarsResource).Groups.FirstOrDefault(g => g.Id == grp.Id) == null)
                {
                    (defaultBindingSource.Current as JarsResource).Groups.Add(grp);
                }
            }
            groupsBindingSource.ResetBindings(false);
        }
Пример #2
0
        private void ctrl_btnManUsers_Click(object sender, EventArgs e)
        {
            IList <SearchEntity <int> > existingUsers = new List <SearchEntity <int> >();
            IList <SearchEntity <int> > AllUsers      = new List <SearchEntity <int> >();

            foreach (JarsResource user in resourceBindingSource.List)
            {
                existingUsers.Add(new SearchEntity <int> {
                    DisplayText = user.DisplayName, ValueId = user.Id, IsSelected = true
                });
            }

            List <JarsResource> AllOpps = ServiceClient.Get(new FindResources()
            {
                IsActive = true, FetchEagerly = false
            }).Resources.ConvertAll(r => r.ConvertTo <JarsResource>());

            foreach (JarsResource user in AllOpps)
            {
                AllUsers.Add(new SearchEntity <int> {
                    DisplayText = user.DisplayName, ValueId = user.Id, IsSelected = false
                });
            }

            IList <SearchEntity <int> > returnList = SelectEntitiesForm.ShowForm(existingUsers, AllUsers, "Select Users");
            //convert the return list to the entities.
            IList <JarsResource> newList = new List <JarsResource>();

            foreach (var sEnt in returnList)
            {
                JarsResource resource = AllOpps.FirstOrDefault(op => op.Id.ToString() == sEnt.ValueId.ToString());
                if (resource != null)
                {
                    newList.Add(resource);
                }
            }

            //see the notes at the top of the class!!
            //we need to make sure we don't end up with a circular reference, so we need to clean the resource group for serialization.

            (defaultBindingSource.Current as ResourceGroupDto).Resources.Clear();

            foreach (var nOp in newList)
            {
                JarsResource op = (defaultBindingSource.Current as JarsResourceGroup).Resources.FirstOrDefault(g => g.Id == nOp.Id);
                if (op == null)
                {
                    if (!nOp.Groups.Contains(defaultBindingSource.Current as JarsResourceGroup))
                    {
                        nOp.Groups.Add(defaultBindingSource.Current as JarsResourceGroup);
                    }

                    (defaultBindingSource.Current as JarsResourceGroup).Resources.Add(nOp);
                }
                else
                {
                    if (!op.Groups.Contains(defaultBindingSource.Current as JarsResourceGroup))
                    {
                        op.Groups.Add(defaultBindingSource.Current as JarsResourceGroup);
                    }
                }
            }
            foreach (var opP in (defaultBindingSource.Current as JarsResourceGroup).Resources)
            {
                foreach (var opPg in opP.Groups)
                {
                    opPg.Resources = null;
                }
            }
            // operativeBindingSource.ResetBindings(false);
            UpdateLinkedBindingSources();
        }