public async Task <bool> AssignUsersToGroup(GroupMemberAssignRequest memberAssignRequest) { UserCredential = memberAssignRequest.Credential; await AuthenticateAsync(); using (var pClient = new PowerBIClient(new Uri(POWER_BI_API_URL), PTokenCredentials)) { var groupSearch = await pClient.Groups.GetGroupsWithHttpMessagesAsync($"id eq '{memberAssignRequest.GroupId}'"); var group = groupSearch.Body.Value.FirstOrDefault(); if (group == null) { throw new ValidationException(PowerResource.ValidationErrorParentGroupNotFoundError); } if (memberAssignRequest.Members.Any()) { memberAssignRequest.Members.ForEach(async s => { try { await pClient.Groups.AddGroupUserWithHttpMessagesAsync(group.Id, new GroupUserAccessRight { EmailAddress = s.MemberEmail, GroupUserAccessRightProperty = s.GroupUserAccessRight.GetRight() }); } catch (Exception e) { throw new ApplicationException(PowerResource.ProcessError_UserAssignment); } }); } } return(true); }
public async Task <bool> AssignPowerBiGroupUsers(GroupMemberAssignRequestVM groupMemberAssignRequest) { var request = new GroupMemberAssignRequest { Credential = new UserData { TenantId = groupMemberAssignRequest.Credential.TenantId, SecretId = groupMemberAssignRequest.Credential.SecretId, ApplicationId = groupMemberAssignRequest.Credential.ApplicationId }, GroupId = groupMemberAssignRequest.GroupId, Members = groupMemberAssignRequest.Members.Select(s => { var membersRights = new MembersRights { MemberEmail = s.MemberEmail, GroupUserAccessRight = s.GroupUserAccessRight }; return(membersRights); }).ToArray() }; var Result = await _powerService.AssignUsersToGroup(request); return(Result); }