private List <Models.RankTime> GetRankTime() { Repository.KartLog _KartLog = new Repository.KartLog(); List <Models.KartLog> listKartLog = _KartLog.GetKartLog(); List <Models.RankTime> rank = null; if (null != listKartLog) { rank = (from pilot in listKartLog group pilot by pilot.PilotId into pilotGroup select new Models.RankTime() { PilotId = pilotGroup.Key, PilotName = pilotGroup.FirstOrDefault(x => x.PilotId == pilotGroup.Key).PilotName, Turns = pilotGroup.Select(x => x.Time).ToList(), ListSpeed = pilotGroup.Select(x => x.AverageSpeed).ToList() }).ToList(); } return(rank); }
public List <Models.Records> GetRecords() { Repository.KartLog _KartLog = new Repository.KartLog(); List <Models.Records> listRecord = null; var rank = GetRankTime(); if (null != rank) { listRecord = new List <Models.Records>(); foreach (var item in rank) { TimeSpan sum = GetTotalTime(item.Turns); int index = 0; listRecord.Add(new Models.Records() { PilotId = item.PilotId, PilotName = item.PilotName, TotalTime = sum, TimeMax = item.Turns.Max <TimeSpan>(), TimeMim = item.Turns.Min <TimeSpan>(), BestLap = ( from t in item.Turns select new { Time = t, id = (index = index + 1) } ).First(x => x.Time == item.Turns.Min <TimeSpan>()).id, Turns = item.Turns, AverageSpeed = GetAverageSpeed(item.ListSpeed), ListSpeed = item.ListSpeed }); listRecord = listRecord.OrderBy(x => x.TotalTime).ToList(); } } return(listRecord); }