public async Task <ExpertTourPredictionsReadDto> Handle(GetPredictionsByTourAndExpert request,
                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            var tourId   = request.TourId;
            var expertId = request.ExpertId;

            var tour = await _context
                       .Tours
                       .FetchWithFullMatchesInfoAndPredictions(FetchMode.ForRead)
                       .WithIdAsync(tourId, cancellationToken);

            var tourNumber   = tour.Number;
            var tournamentId = tour.TournamentId;

            var tournament = await _context.Tournaments.FindAsync(tournamentId);

            var expert = await _context.Experts.FindAsync(expertId);

            var predictions = tour.GetPredictionsForExpert(expertId);

            var expertInfo      = _mapper.Map <ExpertInfoReadDto>(expert);
            var tournamentInfo  = _mapper.Map <TournamentInfoReadDto>(tournament);
            var predictionInfos = _predictionService.ConvertToFullInfoDtos(predictions, _mapper);

            return(new ExpertTourPredictionsReadDto(expertInfo, tournamentInfo, tourNumber, predictionInfos));
        }
Пример #2
0
        public async Task <IEnumerable <ExpertTourPredictionsReadDto> > Handle(GetTourPredictions request,
                                                                               CancellationToken cancellationToken = default(CancellationToken))
        {
            var tourId = request.TourId;

            var tour = await _context
                       .Tours
                       .FetchWithFullPredictionsInfo(FetchMode.ForRead)
                       .WithIdAsync(tourId, cancellationToken);

            var tourNumber   = tour.Number;
            var tournamentId = tour.TournamentId;
            var matches      = tour.Matches;

            var tournament = await _context.Tournaments.FindAsync(tournamentId);

            var predictionsByExpert = _predictionService.GroupPredictionsByExpert(matches);

            var expertTourPredictions = new List <ExpertTourPredictionsReadDto>();

            foreach (var expert in predictionsByExpert.Keys)
            {
                var expertInfo      = _mapper.Map <ExpertInfoReadDto>(expert);
                var tournamentInfo  = _mapper.Map <TournamentInfoReadDto>(tournament);
                var predictionInfos = _predictionService.ConvertToFullInfoDtos(expert.Predictions, _mapper);

                expertTourPredictions.Add(new ExpertTourPredictionsReadDto(expertInfo, tournamentInfo, tourNumber, predictionInfos));
            }

            return(expertTourPredictions);
        }