private void ReadFile(RegisterRaceDTO input) { var file = input.File; var fileReadStream = file.OpenReadStream(); var track = ""; using (var reader = new StreamReader(fileReadStream)) { if (input.RaceType == RaceType.Normal) //Regular race { } else if (input.RaceType == RaceType.League) //League race { Console.WriteLine(reader.ReadLine()); var trackLine = reader.ReadLine(); Console.WriteLine(trackLine); var list = trackLine.Split(","); track = list[1]; track = track.Substring(1, track.Length - 2); Console.WriteLine(reader.ReadLine()); Console.WriteLine(reader.ReadLine()); Console.WriteLine(reader.ReadLine()); Console.WriteLine(reader.ReadLine()); Console.WriteLine(reader.ReadLine()); Console.WriteLine(reader.ReadLine()); } else if (input.RaceType == RaceType.LeageFeature) //League race feature { } else if (input.RaceType == RaceType.LeagueSprint) //League race sprint { } var race = _raceManager.CreateRace(new Race() { RaceNumber = input.RaceNumber, SeasonId = input.SeasonId, Track = track, RaceType = input.RaceType }); var csv = new CsvReader(reader); csv.Configuration.RegisterClassMap <RaceRowCsvModelDTOClassMap>(); csv.Configuration.MissingFieldFound = null; // csv.Read(); // csv.Read(); csv.Read(); csv.ReadHeader(); var records = csv.GetRecords <RaceRowCsvModelDTO>(); foreach (var record in records) { var raceRow = new RaceRow(); raceRow.DriverId = GetDriverId(record); raceRow.Position = record.FinPos; raceRow.Car = record.Car; raceRow.Incidents = record.Inc; raceRow.StartPosition = record.StartPos; raceRow.Points = record.Pts; raceRow.RaceId = race.Id; _raceRowManager.CreateRaceRow(raceRow); } } }
public void RegisterRace(RegisterRaceDTO input) { ReadFile(input); }
public ActionResult Post([FromForm] RegisterRaceDTO input) { _manager.RegisterRace(input); return(Ok("Done")); }