using KSPMasterKey.Shared; using System.Net.Http.Json; namespace KSPMasterKey.Client.Services { public class CustomersService : ICustomers { private readonly HttpClient _http; public List Customers { get; set; } = new List(); public CustomersService(HttpClient http) { _http = http; } public async Task GetCustomerAsync(int id) { Customer? customer = await _http.GetFromJsonAsync($"api/Customer/{id}"); if (customer != null) { return customer; } return new Customer(); } public async Task?> GetCustomersAsync() { if (Customers != null && Customers.Count == 0) { Customers = await _http.GetFromJsonAsync>("api/Customer"); } return Customers; } public async Task SaveCustomerAsync(int id, Customer customer) { CustomerRequest request = new () { Id = id, customer = customer }; await _http.PostAsJsonAsync("api/Customer", request); } } }