presence/Presence.Desktop/Helpers/CsvHelper.cs

42 lines
1.1 KiB
C#
Raw Permalink Normal View History

2024-12-12 07:20:21 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using domain.Request;
using Presence.Desktop.Models;
namespace Presence.Desktop.Helpers
{
public static class CsvHelper
{
public static IEnumerable<AddStudentRequest> ReadCsvStudents(string path)
{
List<AddStudentRequest> students = new List<AddStudentRequest>();
var csvLines = File.ReadAllLines(path, Encoding.GetEncoding("utf-8"));
using (var reader = new StreamReader(path))
{
string line;
while ((line = reader.ReadLine()) != null)
{
var values = line.Split(';');
if (values.Length != 3)
continue;
students.Add(new AddStudentRequest
{
LastName = values[0],
FirstName = values[1],
Patronymic = values[2]
});
}
}
return students;
}
}
}