Backend/e-suite.CustomerApi/e-suite.CustomerApi/User.cs
2026-01-20 21:50:10 +00:00

28 lines
922 B
C#

using e_suite.API.Common.models;
using e_suite.CustomerApi.Helper;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
namespace e_suite.CustomerApi;
public class User
{
public async Task CreateUser(UserRegistration userRegistration)
{
var client = HttpHelper.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiSettings.Instance.Token);
client.BaseAddress = ApiSettings.Instance.BaseUrl;
var json = JsonSerializer.Serialize(userRegistration);
var body = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("User/user", body);
if (response.IsSuccessStatusCode)
return;
var responseBody = await response.Content.ReadAsStringAsync();
throw new Exception(responseBody);
}
}