first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using BethanysPieShopHRM.Shared.Domain;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace Webshop.App.Services
|
||||
{
|
||||
public class EmployeeDataService : IEmployeeDataService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public EmployeeDataService(
|
||||
HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
public async Task<Employee?> AddEmployee(Employee employee)
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync<Employee>("/api/employee", employee);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<Employee>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task DeleteEmployee(int EmployeeId)
|
||||
{
|
||||
await _httpClient.DeleteAsync($"/api/employee/{EmployeeId}");
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Employee>> GetAllEmployees()
|
||||
{
|
||||
return await _httpClient.GetFromJsonAsync<IEnumerable<Employee>>("/api/employee");
|
||||
}
|
||||
|
||||
public async Task<Employee> GetEmployeeDetails(int employeeId)
|
||||
{
|
||||
return await _httpClient.GetFromJsonAsync<Employee>($"api/employee/{employeeId}");
|
||||
}
|
||||
|
||||
public async Task UpdateEmployee(Employee employee)
|
||||
{
|
||||
await _httpClient.PutAsJsonAsync<Employee>("/api/employee", employee);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user