|
|
|
@ -8,11 +8,14 @@ namespace adminBlazor.Services
|
|
|
|
|
public class DataApiService : IDataService
|
|
|
|
|
{
|
|
|
|
|
private readonly HttpClient _http;
|
|
|
|
|
private readonly ILogger<DataApiService> _logger;
|
|
|
|
|
|
|
|
|
|
public DataApiService(
|
|
|
|
|
HttpClient http)
|
|
|
|
|
HttpClient http,
|
|
|
|
|
ILogger<DataApiService> logger)
|
|
|
|
|
{
|
|
|
|
|
_http = http;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Add(UserModel model)
|
|
|
|
@ -22,6 +25,8 @@ namespace adminBlazor.Services
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
|
await _http.PostAsJsonAsync("https://localhost:7234/api/User/", item);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("User API : call of method ADD. Creation of user ID : {Id}.", item.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> Count()
|
|
|
|
@ -31,11 +36,13 @@ namespace adminBlazor.Services
|
|
|
|
|
|
|
|
|
|
public async Task<List<User>> List(int currentPage, int pageSize)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("User API : call of method LIST.");
|
|
|
|
|
return await _http.GetFromJsonAsync<List<User>>($"https://localhost:7234/api/User/?currentPage={currentPage}&pageSize={pageSize}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<User> GetById(int id)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("User API : call of method GetByID.");
|
|
|
|
|
return await _http.GetFromJsonAsync<User>($"https://localhost:7234/api/User/{id}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -44,11 +51,14 @@ namespace adminBlazor.Services
|
|
|
|
|
// Get the item
|
|
|
|
|
var item = UserFactory.Create(model);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("User API : call of method UPDATE on User ID : {Id}.", id);
|
|
|
|
|
|
|
|
|
|
await _http.PutAsJsonAsync($"https://localhost:7234/api/User/{id}", item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("User API : call of method DELETE on User ID : {Id}.", id);
|
|
|
|
|
await _http.DeleteAsync($"https://localhost:7234/api/User/{id}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|