46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using Entities.DTO;
|
|
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
|
|
namespace TechHelper.Client.Services
|
|
{
|
|
public class ClasssServices : IClassServices
|
|
{
|
|
private HttpClient _client;
|
|
private IHttpClientFactory _httpClientFactory;
|
|
|
|
public ClasssServices(HttpClient client, IHttpClientFactory httpClientFactory)
|
|
{
|
|
_client = client;
|
|
_httpClientFactory = httpClientFactory;
|
|
}
|
|
|
|
public Task<ResponseDto> CreateClass(UserRegistrationToClassDto userClass)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<ResponseDto> UserRegister(UserRegistrationToClassDto userRegistrationToClassDto)
|
|
{
|
|
using (_client = _httpClientFactory.CreateClient("Default"))
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
var result = await _client.PostAsJsonAsync("class/userRegiste",
|
|
userRegistrationToClassDto);
|
|
var data = await result.Content.ReadAsStringAsync();
|
|
return new ResponseDto { IsSuccessfulRegistration = result.IsSuccessStatusCode, Errors = new string[] { data } };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ResponseDto { IsSuccessfulRegistration = false, Errors = new string[] { ex.Message } };
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|