Exemplo n.º 1
0
        public void FinishRace(int raceId, RaceTimes[] raceTimes)
        {
            Race currentRace = saveRaceDetails(raceId, raceTimes);

              Clients.Caller.RedirectToRace();
              Clients.Others.getAllLeagues(_repo.GetCurrentLeaderBoards(), currentRace);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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;
        }