public JsonResult GetGroupList(int accountId) { string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name; try { //Check value enter id account if (accountId == 0) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailAndPasswordWrong)); return(Json(MessageResult.GetMessage(MessageType.EMAIL_AND_PASSWORD_WRONG))); } //get group list by owner Id List <GroupOwnerEntity> groupEntities = _groupRepository.GetGroupListByOwnerId(accountId); List <GroupMemberEntity> groupMembers = _groupMemberRepository.GetGroupMemberByAccountId(accountId); if (groupEntities == null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound)); return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND))); } // Create new list result to get data List <GroupListResult> groupListResult = new List <GroupListResult>(); foreach (var groupOwner in groupEntities) { GroupEntity group = _groupRepository.GetGroupById(groupOwner.GroupId); GroupListResult groupList = new GroupListResult(); groupList.groupId = groupOwner.GroupId.ToString("0000"); groupList.groupOwnerId = groupOwner.GroupOwnerId; groupList.ownerGroupId = groupOwner.AccountId; groupList.groupName = group.Name; groupList.description = group.Description; groupListResult.Add(groupList); } foreach (var groupMember in groupMembers) { GroupEntity group = _groupRepository.GetGroupById(groupMember.GroupId); GroupListResult groupList = new GroupListResult(); groupList.groupId = groupMember.GroupId.ToString("0000"); groupList.groupOwnerId = groupMember.GroupMemberId; groupList.ownerGroupId = groupMember.AccountId; groupList.groupName = group.Name; groupList.description = group.Description; groupListResult.Add(groupList); } return(Json(groupListResult.OrderByDescending(a => a.groupId))); } catch (Exception ex) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message)); return(Json(MessageResult.ShowServerError(ex.Message))); } }
public List <PSADGroup> FilterGroups(ADObjectFilterOptions options) { List <PSADGroup> groups = new List <PSADGroup>(); Group group = null; if (!string.IsNullOrEmpty(options.Id)) { try { group = GraphClient.Group.Get(options.Id).Group; } catch { /* The group does not exist, ignore the exception */ } if (group != null) { groups.Add(group.ToPSADGroup()); } } else { GroupListResult result = new GroupListResult(); if (options.Paging) { if (string.IsNullOrEmpty(options.NextLink)) { result = GraphClient.Group.List(options.Mail, options.SearchString); } else { result = GraphClient.Group.ListNext(options.NextLink); } groups.AddRange(result.Groups.Select(g => g.ToPSADGroup())); options.NextLink = result.NextLink; } else { result = GraphClient.Group.List(options.Mail, options.SearchString); groups.AddRange(result.Groups.Select(g => g.ToPSADGroup())); while (!string.IsNullOrEmpty(result.NextLink)) { result = GraphClient.Group.ListNext(result.NextLink); groups.AddRange(result.Groups.Select(g => g.ToPSADGroup())); } } } return(groups); }