diff options
Diffstat (limited to 'Assistant')
-rw-r--r-- | Assistant/IProduct.cs | 9 | ||||
-rw-r--r-- | Assistant/Product.cs | 21 | ||||
-rw-r--r-- | Assistant/SkuAssist.cs | 16 |
3 files changed, 37 insertions, 9 deletions
diff --git a/Assistant/IProduct.cs b/Assistant/IProduct.cs new file mode 100644 index 0000000..aca3ff5 --- /dev/null +++ b/Assistant/IProduct.cs @@ -0,0 +1,9 @@ +namespace Rehau.Sku.Assist +{ + interface IProduct + { + string Sku { get; } + string Name { get; } + string Uri { get; } + } +} diff --git a/Assistant/Product.cs b/Assistant/Product.cs new file mode 100644 index 0000000..17a7065 --- /dev/null +++ b/Assistant/Product.cs @@ -0,0 +1,21 @@ +namespace Rehau.Sku.Assist +{ + public class Product : IProduct + { + public string Sku { get; } + public string Name { get; } + + public string Uri => throw new System.NotImplementedException(); + + public Product(string sku, string name) + { + Sku = sku; + Name = name; + } + + public override string ToString() + { + return $"{this.Name} ({this.Sku})"; + } + } +}
\ No newline at end of file diff --git a/Assistant/SkuAssist.cs b/Assistant/SkuAssist.cs index 1167274..9eb3328 100644 --- a/Assistant/SkuAssist.cs +++ b/Assistant/SkuAssist.cs @@ -1,8 +1,8 @@ -using System.Net.Http; -using System.Threading.Tasks; -using AngleSharp; +using AngleSharp; using System.Linq; using System.Net; +using System.Net.Http; +using System.Threading.Tasks; namespace Rehau.Sku.Assist { @@ -23,16 +23,14 @@ namespace Rehau.Sku.Assist return await context.OpenAsync(req => req.Content(source)); } - public static string GetResultFromDocument(AngleSharp.Dom.IDocument document) + public static IProduct GetProductFromDocument(AngleSharp.Dom.IDocument document) { - var result = document + return document .All .Where(e => e.ClassName == "product-item__desc-top") - .Select(e => new { sku = e.Children[0].TextContent, title = e.Children[1].TextContent.Trim(new[] { '\n', ' ' }) }) - .Where(t => !t.sku.Any(c => char.IsLetter(c))) + .Select(e => new Product(e.Children[0].TextContent, e.Children[1].TextContent.Trim(new[] { '\n', ' ' }))) + // .Where(product => !product.Sku.Any(c => char.IsLetter(c))) .FirstOrDefault(); - - return result == null ? "Не найдено" : $"{result.title} ({result.sku})"; } } } |