2025-01-14 05:59:55 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using CsvHelper;
|
|
|
|
using CsvHelper.Configuration;
|
2025-01-14 14:01:01 +00:00
|
|
|
using RhSolutions.SkuParser.Abstractions;
|
2025-01-14 05:59:55 +00:00
|
|
|
using RhSolutions.SkuParser.Models;
|
|
|
|
|
|
|
|
namespace RhSolutions.SkuParser.Services;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Парсер артикулов и их количества из файлов *.csv
|
|
|
|
/// </summary>
|
2025-01-14 14:01:01 +00:00
|
|
|
public class CommonCsvParser : ISkuParser
|
2025-01-14 05:59:55 +00:00
|
|
|
{
|
2025-01-14 14:01:01 +00:00
|
|
|
public Dictionary<Product, double> ParseProducts(IFormFile file)
|
2025-01-14 05:59:55 +00:00
|
|
|
{
|
|
|
|
using StreamReader reader = new(file.OpenReadStream());
|
|
|
|
var config = new CsvConfiguration(CultureInfo.GetCultureInfo("ru-RU"))
|
|
|
|
{
|
|
|
|
HasHeaderRecord = false,
|
|
|
|
};
|
|
|
|
using CsvReader csvReader = new(reader, config);
|
2025-01-14 14:01:01 +00:00
|
|
|
|
|
|
|
return csvReader.GetRecords<ProductQuantity>()
|
|
|
|
.ToDictionary(pq => new Product() { Sku = pq.Product.Sku }, pq => pq.Quantity);
|
2025-01-14 05:59:55 +00:00
|
|
|
}
|
|
|
|
}
|