Login fix and rename columns in DB
This commit is contained in:
49
WebAPI/dataParsers/csv.parser.cs
Normal file
49
WebAPI/dataParsers/csv.parser.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.Formats.Asn1;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using WebAPI.Models;
|
||||
|
||||
namespace WebAPI.dataParsers
|
||||
{
|
||||
public class csvParser
|
||||
{
|
||||
public List<DataRow> parse(IFormFile file)
|
||||
{
|
||||
List<DataRow> dataRows = new List<DataRow>();
|
||||
|
||||
var stream = new StreamReader(file.OpenReadStream());
|
||||
string content = stream.ReadToEnd();
|
||||
|
||||
List<string> lines = content.Split("\n").ToList();
|
||||
List<List<string>> data = new List<List<string>>();
|
||||
foreach (string line in lines)
|
||||
{
|
||||
data.Add(line.Split(";").ToList());
|
||||
}
|
||||
|
||||
for (int i = 1; i < data[0].Count; i++)
|
||||
{
|
||||
for (int j = 1; j < data.Count; j++) {
|
||||
if (data[j][0].Length > 0)
|
||||
{
|
||||
float value = float.Parse(data[j][i]);
|
||||
if (value > 0)
|
||||
{
|
||||
DataRow dataRow = new DataRow();
|
||||
dataRow.Id = Guid.NewGuid();
|
||||
dataRow.Code = data[0][i];
|
||||
dataRow.Desc1 = data[j][0];
|
||||
dataRow.Value = value;
|
||||
dataRows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return dataRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user