Files
TechHelper/TechHelper.Client/Services/ClasssServices.cs
2025-05-23 19:03:00 +08:00

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 } };
}
}
}
}
}