public questStatus Read(UserGroupsViewModel viewModel, out UserGroupsViewModel userGroupsViewModel) { // Initialize questStatus status = null; userGroupsViewModel = null; UserId userId = new UserId(viewModel.Id); // Get the user User user = null; UsersMgr usersMgr = new UsersMgr(this.UserSession); status = usersMgr.Read(userId, out user); if (!questStatusDef.IsSuccess(status)) { return(status); } // Get groups List <SearchField> searchFieldList = new List <SearchField>(); SearchOptions searchOptions = new SearchOptions(); searchOptions.SearchFieldList = searchFieldList; QueryOptions queryOptions = new QueryOptions(); queryOptions.SearchOptions = searchOptions; QueryResponse queryResponse = null; List <Group> groupList = null; GroupsMgr groupsMgr = new GroupsMgr(this.UserSession); status = groupsMgr.List(queryOptions, out groupList, out queryResponse); if (!questStatusDef.IsSuccess(status)) { return(status); } // Get user groups List <Group> userGroupList = null; AccountMgr accountMgr = new AccountMgr(this.UserSession); status = accountMgr.GetUserGroups(userId, out userGroupList); if (!questStatusDef.IsSuccess(status)) { return(status); } // Remove from groups lists whatever groups the user is already in. List <Group> unassignedGroupList = new List <Group>(); foreach (Group group in groupList) { Group userGroup = userGroupList.Find(delegate(Group g) { return(g.Id == group.Id); }); if (userGroup == null) { unassignedGroupList.Add(group); } } // Sort group lists unassignedGroupList.Sort(delegate(Group i1, Group i2) { return(i1.Name.CompareTo(i2.Name)); }); userGroupList.Sort(delegate(Group i1, Group i2) { return(i1.Name.CompareTo(i2.Name)); }); // Transfer model userGroupsViewModel = new UserGroupsViewModel(this.UserSession, viewModel); UserEditorViewModel userEditorViewModel = new UserEditorViewModel(); BufferMgr.TransferBuffer(user, userEditorViewModel); userGroupsViewModel.User = userEditorViewModel; foreach (Group group in unassignedGroupList) { BootstrapTreenodeViewModel groupNode = null; status = FormatBootstrapTreeviewNode(group, out groupNode); if (!questStatusDef.IsSuccess(status)) { return(status); } userGroupsViewModel.Groups.Add(groupNode); } foreach (Group group in userGroupList) { BootstrapTreenodeViewModel userGroupNode = null; status = FormatBootstrapTreeviewNode(group, out userGroupNode); if (!questStatusDef.IsSuccess(status)) { return(status); } userGroupsViewModel.UserGroups.Add(userGroupNode); } return(new questStatus(Severity.Success)); }