RhSolutions-AddIn/src/Services/RhDatabaseClient.cs

35 lines
931 B
C#
Raw Normal View History

2022-12-20 12:03:05 +03:00
using Newtonsoft.Json;
2022-12-20 12:41:46 +03:00
using RhSolutions.AddIn;
2022-12-20 13:00:16 +03:00
using RhSolutions.Models;
2022-12-20 12:03:05 +03:00
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
2022-12-20 12:27:47 +03:00
namespace RhSolutions.Services
2022-12-20 12:03:05 +03:00
{
public static class RhDatabaseClient
{
2022-12-20 12:27:47 +03:00
private static HttpClient httpClient = RhSolutionsAddIn.httpClient;
2022-12-20 12:03:05 +03:00
public static async Task<object> GetProduct(string line)
{
string request = @"https://rh.cebotari.ru/api/search?query=" + line;
string response = await httpClient.GetStringAsync(request);
2022-12-20 13:00:16 +03:00
var products = JsonConvert.DeserializeObject<IEnumerable<Product>>(response);
2022-12-20 12:03:05 +03:00
var product = products.FirstOrDefault();
if (product == null)
{
return null;
}
else
{
2022-12-20 13:00:16 +03:00
return $"{product.ProductSku} {product.Name}";
2022-12-20 12:03:05 +03:00
}
}
}
}