aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2025-01-14 14:01:01 +0000
committerSerghei Cebotari <serghei@cebotari.ru>2025-01-14 14:01:01 +0000
commita542bfb7f4ceee8b49cf8fcadf64ffb72cc97da5 (patch)
tree5e9563638eb09a4c3a1c717a6f238139fc66dc53 /RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs
parente2ac0c46c1a1085ab7e7597e463e73f371ce2791 (diff)
Common Parsing Method
Diffstat (limited to 'RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs')
-rw-r--r--RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs b/RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs
new file mode 100644
index 0000000..e88ba25
--- /dev/null
+++ b/RhSolutions.SkuParser.Api/Services/CommonCsvParser.cs
@@ -0,0 +1,26 @@
+using System.Globalization;
+using CsvHelper;
+using CsvHelper.Configuration;
+using RhSolutions.SkuParser.Abstractions;
+using RhSolutions.SkuParser.Models;
+
+namespace RhSolutions.SkuParser.Services;
+
+/// <summary>
+/// Парсер артикулов и их количества из файлов *.csv
+/// </summary>
+public class CommonCsvParser : ISkuParser
+{
+ public Dictionary<Product, double> ParseProducts(IFormFile file)
+ {
+ using StreamReader reader = new(file.OpenReadStream());
+ var config = new CsvConfiguration(CultureInfo.GetCultureInfo("ru-RU"))
+ {
+ HasHeaderRecord = false,
+ };
+ using CsvReader csvReader = new(reader, config);
+
+ return csvReader.GetRecords<ProductQuantity>()
+ .ToDictionary(pq => new Product() { Sku = pq.Product.Sku }, pq => pq.Quantity);
+ }
+}