添加项目文件。
This commit is contained in:
45
TechHelper.Client/Services/ClasssServices.cs
Normal file
45
TechHelper.Client/Services/ClasssServices.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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 } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
12
TechHelper.Client/Services/IClassServices.cs
Normal file
12
TechHelper.Client/Services/IClassServices.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Entities.DTO;
|
||||
using System.Net;
|
||||
using TechHelper.Services;
|
||||
|
||||
namespace TechHelper.Client.Services
|
||||
{
|
||||
public interface IClassServices
|
||||
{
|
||||
public Task<ResponseDto> UserRegister(UserRegistrationToClassDto userRegistrationToClassDto);
|
||||
public Task<ResponseDto> CreateClass(UserRegistrationToClassDto userClass);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user