aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Api/Services/CsvParser.cs
blob: 2776721cbf61caf49d3a4ab90c38721041c12953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System.Globalization;
using CsvHelper;
using CsvHelper.Configuration;
using RhSolutions.SkuParser.Models;

namespace RhSolutions.SkuParser.Services;

/// <summary>
/// Парсер артикулов и их количества из файлов *.csv 
/// </summary>
public class CsvParser : ISkuParser
{
	public IEnumerable<ProductQuantity> 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<ProductQuantity>().ToList();
	}
}