public void AddLap() { var newLap = new UserLap { SetupSheetID = new Guid(), LapTime = TimeSpan.Zero }; if (SelectedLap == null || SelectedLap.InLap) { var lastNonInLap = Laps.LastOrDefault(x => x.InLap == false); if (lastNonInLap != null) { newLap.LapNumber = lastNonInLap.LapNumber + 1; } else { newLap.LapNumber = Laps.Count() + 1; } } else { newLap.LapNumber = Laps.Count() + 1; } //bump the lap number of every lap beyond the insert point. for (var i = newLap.LapNumber - 1; i < Laps.Count(); i++) { Laps[i].LapNumber++; } var lvm = new LapViewModel { Lap = newLap }; Laps.Add(lvm); var lastOrDefault = Laps.LastOrDefault(x => x.InLap == false); SelectedLap = lastOrDefault; }
public decimal GetAvarageSpeed() { var sum = Laps.Sum(l => l.AvarageSpeed); return(sum / Laps.Count()); }