Work with groups
This article describes how to create a new group, add a user to a group, and get a list of group members.
Getting started
You will need the following tools and features:
Knowledge on how to use API key in FastReport Corporate Server.
This article does not include the information about authentication and authorization.
A C# code editor or a text editor like Visual Studio Code.
Active subscription for FastReport.Cloud with two slots for the user.
Internet access.
Please, note: This tutorial assumes that you already know how to develop your application with the C# programming language.
Please, note: The descriptions above are provided for the recommended tools.
Remark
Please, note: It is possible to add a user to a group only if the user is member of the subscription.
Please, note: You can add a user to a group only by the identifier.
Instructions
To create a new group, you need a subscription identifier and the name of the new group.
To get subscription identifier, use <xref:FastReport.Cloud.ISubscriptionsClient.GetSubscriptionsAsync(System.Nullable{System.Int32},System.Nullable{System.Int32})> method .
public async Task<string> GetSubscriptionId(HttpClient httpClient) { ISubscriptionsClient subscriptionsClient = new SubscriptionsClient(httpClient); SubscriptionsVM subscriptions = await subscriptionsClient.GetSubscriptionsAsync(0, 10); SubscriptionVM subscription = subscriptions.Subscriptions.First(); return subscription.Id; }
In this example, the function requests the first 10 subscriptions from the user's list of subscriptions, selects the first subscription, and returns its identifier.
To create a new group, use the <xref:FastReport.Cloud.IGroupsClient.CreateGroupAsync(FastReport.Cloud.CreateGroupVM)> method.
public async Task<string> CreateGroup(HttpClient httpClient, string subscriptionId, string groupName) { IGroupsClient groupsClient = new GroupsClient(httpClient); CreateGroupVM viewModel = new CreateGroupVM() { Name = groupName, SubscriptionId = subscriptionId }; GroupVM group = await groupsClient.CreateGroupAsync(viewModel); return group.Id; }
In this example, the function creates a new group with the group with title
groupName
for the subscription with the identifiersubscriptionId
. As a result, the function will return the identifier of the created group.To add a new user to the group, use the <xref:FastReport.Cloud.IGroupUsersClient.AddUserToGroupAsync(System.String,System.String)> method.
public async Task AddUser(HttpClient httpClient, string groupId, string userId) { IGroupUsersClient groupUsersClient = new GroupUsersClient(httpClient); await groupUsersClient.AddUserToGroupAsync(groupId, userId); }
In this example, the function adds the user with the identifier
userId
to the group with the identifiergroupId
.To get a list of the group members, use the <xref:FastReport.Cloud.IGroupUsersClient.GetUsersInGroupAsync(System.String,System.Nullable{System.Int32},System.Nullable{System.Int32})> method.
public async Task<IEnumerable<string>> GetUsers(HttpClient httpClient, string groupId) { IGroupUsersClient groupUsersClient = new GroupUsersClient(httpClient); GroupUsersVM users = await groupUsersClient.GetUsersInGroupAsync(groupId, 0, 10); return users.Users.Select(m => m.UserId); }
In this example, the function requests for the first 10 users in the group with the identifier
groupId
.