public async Task AddUser(ApplicationUser user)
{
var addUserURL = Urls.AddUser;
var tokenResult = await GetTokenForAdmin();
var parameters = new MultipartFormDataContent
{
{ new StringContent(tokenResult.token), "token" },
{ new StringContent("json"), "f" },
{ new StringContent(user.Email), "username" },
{ new StringContent(user.Email), "email" },
{ new StringContent("P@ssw0rd"), "password" },
{ new StringContent(user.FirstName), "firstname" },
{ new StringContent(user.LastName), "lastname" },
{ new StringContent("org_user"), "role" },
{ new StringContent("creatorUT"), "userLicenseTypeId" },
};
var result = await HttpClient.PostAsync(addUserURL, parameters);
if (result == null)
{
throw new InvalidDataException($"{nameof(AddUser)} POST to {addUserURL} returned null result");
}
else if (result.Content == null)
{
throw new InvalidDataException($"{nameof(AddUser)} POST to {addUserURL} returned null result.Content");
}
using var reader = new StreamReader(await result.Content.ReadAsStreamAsync());
var addUserResult = await reader.ReadToEndAsync();
dynamic addUserResponse = JsonConvert.DeserializeObject(addUserResult);
if (addUserResponse.status != "success")
{
throw new Exception($"Failed to add user to ArcGIS Portal. Error: {addUserResponse.error.code} {addUserResponse.error.message}");
}
}