1
0

27 lines
801 B
C#
Raw Normal View History

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
2025-01-15 15:20:31 +03:00
return csvReader.GetRecords<SkuQuantity>()
.ToDictionary(pq => new Product() { Sku = pq.Sku }, pq => pq.Quantity);
2025-01-14 05:59:55 +00:00
}
}