public void FinishRace(int raceId, RaceTimes[] raceTimes) { Race currentRace = saveRaceDetails(raceId, raceTimes); Clients.Caller.RedirectToRace(); Clients.Others.getAllLeagues(_repo.GetCurrentLeaderBoards(), currentRace); }
public void FinishRaceString(int raceId, RaceTimesString[] raceTimes) { var newRaceTimes = new RaceTimes[raceTimes.Length]; for (int i = 0; i < raceTimes.Length; i++) { string timeString = raceTimes[i].RaceTime; while (timeString.ToCharArray().Count(c => c == ':') < 2) { timeString = "00:" + timeString; } var raceTime = TimeSpan.Parse(timeString); newRaceTimes[i] = new RaceTimes{ RacerId = raceTimes[i].RacerId, RaceTime = (int)Math.Round(raceTime.TotalMilliseconds)}; } Race currentRace = saveRaceDetails(raceId, newRaceTimes); Clients.Caller.RedirectToRace(); Clients.Others.getAllLeagues(_repo.GetCurrentLeaderBoards(), currentRace); }
private Race saveRaceDetails(int raceId, RaceTimes[] raceTimes) { var currentRace = _repo.GetRace(raceId); currentRace.IsComplete = true; var winningTime = raceTimes.Min(r => r.RaceTime); foreach (var driver in currentRace.Drivers) { driver.Racer.IsWaitingForRace = false; driver.RawRaceTime = raceTimes.Single(rt => rt.RacerId == driver.RacerId.ToString(CultureInfo.InvariantCulture)).RaceTime; driver.Winner = driver.RawRaceTime == winningTime; if (driver.RawRaceTime < driver.Racer.RawBestTime || driver.Racer.RawBestTime == 0) { driver.NewPersonalBest = true; driver.Racer.RawBestTime = driver.RawRaceTime; } } _repo.Save(); return currentRace; }