using System; using myBlazorApp.Components; using myBlazorApp.Factories; using myBlazorApp.Models; using static System.Net.WebRequestMethods; namespace myBlazorApp.Services { public class DataApiService : IDataService { private readonly HttpClient _http; public DataApiService( HttpClient http) { _http = http; } public async Task Add(ItemModel model) { // Get the item var item = ItemFactory.Create(model); // Save the data await _http.PostAsJsonAsync("https://localhost:8635/api/Crafting/", item); } public async Task Count() { return await _http.GetFromJsonAsync("https://localhost:8635/api/Crafting/count"); } public async Task> List(int currentPage, int pageSize) { return await _http.GetFromJsonAsync>($"https://localhost:8635/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}"); } public async Task GetById(int id) { return await _http.GetFromJsonAsync($"https://localhost:8635/api/Crafting/{id}"); } public async Task Update(int id, ItemModel model) { // Get the item var item = ItemFactory.Create(model); await _http.PutAsJsonAsync($"https://localhost:8635/api/Crafting/{id}", item); } public async Task Delete(int id) { await _http.DeleteAsync($"https://localhost:8635/api/Crafting/{id}"); } public async Task> GetRecipes() { return await _http.GetFromJsonAsync>("https://localhost:8635/api/Crafting/recipe"); } /* TASKS FOR INVENTORY */ public async Task> GetInventoryItems() { return await _http.GetFromJsonAsync>("https://localhost:8635/api/Inventory"); } public async Task UpdateInventory(string[] infos) { await _http.PutAsJsonAsync("https://localhost:8635/api/Inventory", infos); } } }