27 lines
801 B
C#
27 lines
801 B
C#
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<SkuQuantity>()
|
|
.ToDictionary(pq => new Product() { Sku = pq.Sku }, pq => pq.Quantity);
|
|
}
|
|
}
|