mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
Сделал привязку местоположений и принтеров к местоположениям
This commit is contained in:
1 parent
d69a5689e8
commit
13b3513d2d
49 files changed
+705
-1323
No files matched your search
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CartriX.Shared.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CartriX.Shared.RequestsToApi
|
||||
{
|
||||
public static class PrinterApiRequest
|
||||
{
|
||||
static readonly HttpClient client = new HttpClient();
|
||||
public static async Task<Printer?> PrinterByIdAsync(int id)
|
||||
{
|
||||
if (id <= 0) return null;
|
||||
|
||||
var url = $"http://localhost:5197/api/Printer/{id}";
|
||||
|
||||
try
|
||||
{
|
||||
var response = await client.GetAsync(url).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
return JsonConvert.DeserializeObject<Printer?>(content);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
Console.WriteLine($"JSON error: {e.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user