public async Task <IActionResult> GetBonusPredictions(GetBonusPredictionQuery query) { var userBetGroup = await GetCurrentUserBetGroup(query.BetGroupId); var bonusPredictions = await _dbContext.BonusPredictions .Where(q => q.UserBetGroupId == userBetGroup.Id) .Select(m => new { m.TeamId, m.WorldCupGroupId, WorldCupGroupName = m.WorldCupGroup.Name, m.Id, m.BonusPredictionType }) .ToArrayAsync(); return(Ok(bonusPredictions)); }
public async Task <IActionResult> GetBonusPredictionsScores(GetBonusPredictionQuery query) { var result = new List <BonusPredictionsScoreQueryResult>(); var userBetGroup = await GetCurrentUserBetGroup(query.BetGroupId); var bonusPredictions = await _dbContext.BonusPredictions .Where(q => q.UserBetGroupId == userBetGroup.Id) .Select(m => new { m.TeamId, m.WorldCupGroupId, WorldCupGroupName = m.WorldCupGroup.Name, m.Id, m.BonusPredictionType }) .ToArrayAsync(); var groups = await _dbContext.WorldCupGroups.ToArrayAsync(); var scoreCalculator = new ScoreCalculator(null, null); foreach (var group in groups) { var groupPredictions = bonusPredictions .Where(q => q.WorldCupGroupId == group.Id) .ToArray(); var winner = groupPredictions .Single(q => q.BonusPredictionType == BonusPredictionType.FirstTeamInGroup).TeamId; var runnerup = groupPredictions .Single(q => q.BonusPredictionType == BonusPredictionType.SecondTeamInGroup).TeamId; var score = scoreCalculator .CalculateBonusScoreForGroup(winner, runnerup, group); var record = new BonusPredictionsScoreQueryResult() { Score = score, BonusType = group.Name }; result.Add(record); } var match = await _dbContext .Matches .Include(q => q.AwayTeamScore.Team) .Include(q => q.HomeTeamScore.Team) .SingleOrDefaultAsync(q => q.MatchType == MatchType.Final); var stat = new BonusPredictionsScoreQueryResult() { Score = scoreCalculator.CalculateBonusScoreForTopNotch ( bonusPredictions.Single(q => q.BonusPredictionType == BonusPredictionType.FirstTeamInWorldCup).TeamId, match, BonusPredictionType.FirstTeamInWorldCup), BonusType = BonusPredictionType.FirstTeamInWorldCup.ToString() }; result.Add(stat); stat = new BonusPredictionsScoreQueryResult() { Score = scoreCalculator.CalculateBonusScoreForTopNotch ( bonusPredictions.Single(q => q.BonusPredictionType == BonusPredictionType.SecondTeamInWorldCup).TeamId, match, BonusPredictionType.SecondTeamInWorldCup), BonusType = BonusPredictionType.SecondTeamInWorldCup.ToString() }; result.Add(stat); match = await _dbContext .Matches .Include(q => q.AwayTeamScore.Team) .Include(q => q.HomeTeamScore.Team) .SingleOrDefaultAsync(q => q.MatchType == MatchType.ThirdPlacePlayOff); stat = new BonusPredictionsScoreQueryResult() { Score = scoreCalculator.CalculateBonusScoreForTopNotch ( bonusPredictions.Single(q => q.BonusPredictionType == BonusPredictionType.ThirdTeamInWorldCup).TeamId, match, BonusPredictionType.ThirdTeamInWorldCup), BonusType = BonusPredictionType.ThirdTeamInWorldCup.ToString() }; result.Add(stat); return(Ok(result)); }