コード例 #1
0
        public async Task <ResponseWrapper <SimulationResponse> > SimulateRound([FromBody] SimulateRoundRequest request)
        {
            var tournament = await fantasySoccerService.GetTournament(request.TournamentId);

            var matchSimulationResults = await simulationService.SimulateTournamentRound(tournament.ID, request.Round);

            var playersPerformances = new List <MatchFutbolPlayerPerformance>();
            var matches             = new List <Match>();

            matchSimulationResults.ForEach(msr =>
            {
                playersPerformances.AddRange(msr.PlayersPerformance);
                matches.Add(msr.Match);
            });

            await fantasySoccerService.UpdateMatchesAsync(matches);

            await fantasySoccerService.AddMatchFutbolPlayersPerformancesAsync(playersPerformances);

            tournament.CurrentRound++;
            await fantasySoccerService.UpdateTournament(tournament);

            return(new ResponseWrapper <SimulationResponse>
            {
                StatusCode = Models.Responses.StatusCode.OK,
                Response = new SimulationResponse
                {
                    TournamentId = request.TournamentId,
                    TournamentName = tournament.Name,
                    CurrentRound = tournament.CurrentRound,
                    Matches = matches
                }
            });
        }