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 } }); }
public async Task <ResponseWrapper <List <Match> > > GetMatchesByRound([FromQuery] SimulateRoundRequest request) { try { var matches = await fantasySoccerService.GetMatches(request.TournamentId, request.Round); return(new ResponseWrapper <List <Match> > { StatusCode = Models.Responses.StatusCode.OK, Response = matches }); } catch { return(new ResponseWrapper <List <Match> > { StatusCode = Models.Responses.StatusCode.BadRequest, Message = "Couldn't get the round data. \nTry again later" }); } }