private async Task CollectBestTimesCube(string userId, BestTimesViewModel model) { var allCubes = await _cubeCollectionService.GetAllCubesOfUserAsync(userId); var allSeries = await _seriesService.GetAllSeriesOfUserAsync(userId); if (allCubes != null && allSeries != null) { foreach (var cube in allCubes) { var options = allSeries .Where(s => s.Cube == cube) .Select(s => s.SerieOption) .Distinct() .ToList(); var singleCubeBestTimes = new BestTimesCollectionViewModel() { Description = string.Format("{0} {1} {2}", cube.Manufacturer.Name, cube.ModelName, cube.PlasticColor.Name), }; foreach (var option in options) { var serie = allSeries .Where(s => s.Cube == cube && s.SerieOption == option) .OrderBy(s => s.ShortestResult) .ToList() .First(); var solve = (await _seriesService.GetAllSolvesOfSerieAsync(serie.Identity)) .OrderBy(s => s.Duration) .FirstOrDefault(); if (solve != null) { singleCubeBestTimes.Times.Add(new BestTimeViewModel() { SerieID = serie.Identity, Duration = solve.Duration, TimeStamp = solve.FinishTimeSpan, CategoryOption = option.Name, DNF = solve.DNF, Penalty = solve.PenaltyTwoSeconds, }); } } model.TimeCollection.Add(singleCubeBestTimes); } model.TimeCollection .OrderBy(ct => ct.Description); foreach (var times in model.TimeCollection) { times.Times = times.Times.OrderBy(t => t.Duration).ToList(); } } }
private async Task <BestTimesViewModel> CollectBestTimes(string userId, int type) { var outputModel = new BestTimesViewModel() { UserId = userId, UserName = (await _userManager.FindByIdAsync(userId))?.UserName, ViewType = type == 1 ? 1 : 0, }; if (type == 1) { await CollectBestTimesCube(userId, outputModel); } else { await CollectBestTimesCategory(userId, outputModel); } return(outputModel); }