using System.Globalization;
using CsvHelper;
using CsvHelper.Configuration;
using RhSolutions.SkuParser.Models;
namespace RhSolutions.SkuParser.Services;
///
/// Парсер артикулов и их количества из файлов *.csv
///
public class CsvParser : ISkuParser
{
public async Task> ParseProducts(IFormFile file)
{
using MemoryStream memoryStream = new(new byte[file.Length]);
await file.CopyToAsync(memoryStream);
memoryStream.Position = 0;
using StreamReader reader = new(memoryStream);
var config = new CsvConfiguration(CultureInfo.GetCultureInfo("ru-RU"))
{
HasHeaderRecord = false,
};
using CsvReader csvReader = new(reader, config);
return csvReader.GetRecords().ToList();
}
}