LootBoxGenerator/LootBoxSimulator/Program.cs
2024-12-16 14:24:55 +03:00

28 lines
812 B
C#

using System.Reflection.Emit;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Channels;
using LootBoxSimulator.Models.DAO;
RemoteDatabaseContext db = new RemoteDatabaseContext();
Console.WriteLine("Enter path to file");
string? path = Console.ReadLine();
if (path == null) return;
if (!bool.TryParse(Console.ReadLine(), out bool HaveHeader)) return;
StreamReader file = new StreamReader(path);
string row = String.Empty;
if(HaveHeader) row = file.ReadLine();
Console.WriteLine(row);
while ((row = file.ReadLine()) != null)
{
var line = row.Split(',');
if(!decimal.TryParse(line[2], out var decimalValue)) continue;
RateDao dao = new RateDao
{
Name = line[0],
Color = line[1],
Rate = decimalValue
};
db.Rates.Add(dao);
}
db.SaveChanges();