private async Task <(List <MarketPlaceItems>, int)> GetMarketPlaceItems(int pageSize, int page, string searchedFirstNamePlayer = "", string searchedLastNamePlayer = "") { Func <FutbolPlayer, bool> filterPlayer = null; if (!string.IsNullOrWhiteSpace(searchedFirstNamePlayer) || !string.IsNullOrWhiteSpace(searchedLastNamePlayer)) { filterPlayer = futbolPlayer => futbolPlayer.Name.ToLower().Contains(searchedFirstNamePlayer?.ToLower() ?? " ") || futbolPlayer.LastName.ToLower().Contains(searchedLastNamePlayer?.ToLower() ?? " "); } var skip = (page - 1) * pageSize; var futbolPlayerPaginated = await fantasySoccerService.GetFutbolPlayersStoreAsync(pageSize, skip, filterPlayer); var teams = await fantasySoccerService.GetFutbolTeamsAsync(); var userTeam = await fantasySoccerService.GetUserTeamAsync(); var marketPlaceItems = futbolPlayerPaginated.PaginatedItems.Join(teams, p => p.FutbolTeamID, t => t.ID, (p, t) => new MarketPlaceItems { FutbolPlayer = p, FutbolTeamName = t.Name, UserTeamContainsPlayer = userTeam.Players != null && userTeam.Players.Any(teamPlayer => teamPlayer.ID == p.ID) }).ToList(); return(marketPlaceItems, futbolPlayerPaginated.TotalItems); }
public async Task <ActionResult> DownloadPlayers() { var players = await fantasySoccerService.GetFutbolPlayersStoreAsync(); var data = JsonSerializer.Serialize(players.PaginatedItems, serializerOptions); var bytes = Encoding.UTF8.GetBytes(data); return(new FileContentResult(bytes, "application/json") { FileDownloadName = "players.json" }); }
public async Task <List <MatchSimulationResult> > SimulateTournamentRound(string tournamentId, int round) { var matches = await fantasySoccerService.GetMatches(tournamentId, round); var matchSimulationResults = new List <MatchSimulationResult>(); var futbolPlayers = await fantasySoccerService.GetFutbolPlayersStoreAsync(); var futbolPlayersGroupByTeam = futbolPlayers.PaginatedItems.ToLookup(fp => fp.FutbolTeamID, fp => fp); foreach (var match in matches) { var localTeam = futbolPlayersGroupByTeam[match.LocalFutbolTeamID]; var visitorTeam = futbolPlayersGroupByTeam[match.VisitorFutbolTeamID]; matchSimulationResults.Add(SimulateMatch(match, localTeam.ToList(), visitorTeam.ToList())); } return(matchSimulationResults); }