User service
Warning
Before you begin set the Access API Key as described in Getting started
There two types of users, host user, the first user that registered to BALKAN OrgChart and guest users, the guest users are the invited users. The guests users are using the resources from the host user.
With the user service you can:
- Invite and create guests
- Update guest
- List guests
- Remove guest
Invite and create guests
First you can create an invitation link or invitation key
var userService = new UserService();
var optionsInvite = new OptionsInvite
{
Emails = "john.smith@balkan.app,ana.garson@balkan.app",
Permissions = new Dictionary<string, bool> {
{"Read", true },
{"Write", true }
},
SendEmails = false
};
var resultInvite = userService.Invite(optionsInvite);
Visualized result:
The first option parameter is the emails separated by comma, invited guests will have Read and Write permissions then set the SendEmails option parameter to false if you want to send inviotation emails using you email service provider, to do that iterate Invitations result parameter, it contains invitation link and email.
Instead of sending invitation email you can create the guests instead
Here is an example how to create an account for the first invited guest
var firstInvitation = resultInvite.Invitations.First();
var optionsSignUp = new OptionsSignUp
{
InvitationKey = firstInvitation.Key,
DisplayName = "Jack Hill",
Email = firstInvitation.Email,
Password = "ADSG45Ss_sf!#f",
SendEmail = false
};
var resultCreate = userService.Create(optionsSignUp);
Visualized result:
Update guest
Now you can update the permissions for a guest
public static void UpdateGuest()
{
var userService = new UserService();
var resultUpdateGuest = userService.UpdateGuest(new OptionsUpdateGuest
{
Email = "john.smith@balkan.app",
Permissions = new Dictionary<string, bool> {
{"Read", true },
{"Write", true },
{"Invite", true }
}
});
if (!resultUpdateGuest.IsSuccess)
{
Console.WriteLine(resultUpdateGuest.Error);
}
}
Visualized result:
List guests
public static void ListGuests()
{
var userService = new UserService();
var resultListGuests = userService.ListGuests(new OptionsList
{
Skip = 0,
Take = 10
});
if (!resultListGuests.IsSuccess)
{
Console.WriteLine(resultListGuests.Error);
}
else
{
Console.WriteLine("------invited-------");
foreach (var invited in resultListGuests.Invited)
{
Console.WriteLine(invited);
}
Console.WriteLine("------accepted-------");
foreach (var accepted in resultListGuests.Accepted)
{
Console.WriteLine(accepted);
}
Console.WriteLine($"Accepted total count: {resultListGuests.AcceptedCount}");
Console.WriteLine($"Invited total count: {resultListGuests.InvitedCount}");
}
}
Remove guest
public static void RemoveGuest()
{
var userService = new UserService();
var resultRemoveGuest = userService.RemoveGuest(new OptionsRemoveGuest
{
Email = "john.smith@balkan.app"
});
if (!resultRemoveGuest.IsSuccess)
{
Console.WriteLine(resultRemoveGuest.Error);
}
}
If you want to delete all guests call "Empty" method
Note
The demo is located at GitHub