Try parse sku from input line on Rhsolutions function apply

This commit is contained in:
Sergey Chebotar 2022-12-22 16:00:38 +03:00
parent f267b27375
commit c47301c0db

View File

@ -17,9 +17,9 @@ namespace RhSolutions.Services
{ {
string request = string.Empty; string request = string.Empty;
if (line.IsRehauSku()) if (Sku.TryParse(line, out var skus))
{ {
request = @"https://rh.cebotari.ru/api/products/" + line; request = @"https://rh.cebotari.ru/api/products/" + skus.FirstOrDefault().ToString();
} }
else else
@ -31,7 +31,7 @@ namespace RhSolutions.Services
try try
{ {
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
string json = await response.Content.ReadAsStringAsync(); string json = await response.Content.ReadAsStringAsync();
var product = JsonConvert.DeserializeObject<IEnumerable<Product>>(json) var product = JsonConvert.DeserializeObject<IEnumerable<Product>>(json)
.FirstOrDefault(); .FirstOrDefault();
@ -42,14 +42,7 @@ namespace RhSolutions.Services
} }
else else
{ {
if (line.IsRehauSku()) return $"{product.ProductSku} {product.Name}";
{
return product.Name;
}
else
{
return $"{product.ProductSku} {product.Name}";
}
} }
} }
catch catch