1
0
This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
RhSolutions.SkuParser/RhSolutions.SkuParser.Api/Services/CsvParser.cs

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();
}
}