29 lines
806 B
C#
29 lines
806 B
C#
using System.Globalization;
|
|
using CsvHelper;
|
|
using CsvHelper.Configuration;
|
|
using RhSolutions.SkuParser.Models;
|
|
|
|
namespace RhSolutions.SkuParser.Services;
|
|
|
|
/// <summary>
|
|
/// Парсер артикулов и их количества из файлов *.csv
|
|
/// </summary>
|
|
public class CsvParser : ISkuParser
|
|
{
|
|
public async Task<IEnumerable<ProductQuantity>> 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<ProductQuantity>().ToList();
|
|
}
|
|
}
|