public async Task <ResultsEngineStatuses> Process(ITeamResultEngineContext context, IGameResults request, ResultsEngineResponse response) { if (request.GameResults != null && request.GameResults.Count > 0) { var playerIDs = request.GameResults.SelectMany(x => x.AllPlayers).ToArray(); await context.PreloadPlayers(playerIDs); ITeamMatchModel matchModel = await context.Fixture.GetMatch(request.MatchID); var competition = context.Competition; foreach (var gameResult in request.GameResults) { if (matchModel.GameExists(gameResult.MatchFormatXGameVariationID)) { await matchModel.UpdateGame(gameResult); } else { await matchModel.AddGame(gameResult); } } } return(ResultsEngineStatuses.Success); }
public async Task <ResultsEngineStatuses> Process(ITeamResultEngineContext context, IGameResults request, ResultsEngineResponse response) { var ok = true; var ruleSet = await context.GetRuleSet(); RuleSetXRule rule = await context.GetRuleSpecification(Entities.Rule.Rules.CheckMaximumGamesForHigherRankedCompetition); if (ruleSet.Competitions.Count > 0) { int maxGames = rule.DataInt1.Value; ITeamMatchModel match = await context.Fixture.GetMatch(request.MatchID); BowlsResults.Common.Domain.Entities.Team homeTeam = match.Data.Home; BowlsResults.Common.Domain.Entities.Team awayTeam = match.Data.Away; var statistics = await context.GetCompetitionPlayerGameStatistic(request, match); var competitionIDs = ruleSet.Competitions.Select(x => x.CompetitionID).ToList(); // Get index of the competition var index = competitionIDs.FindIndex(x => x == context.Competition.ID); // Remove all other competitions to leave only higher ones competitionIDs.RemoveRange(index, competitionIDs.Count - index); var allPlayers = context.GetAllPlayersWithTeam(request, match); foreach (var(playerID, team) in allPlayers) { ok &= await this.Validate(context, response, statistics, competitionIDs, maxGames, playerID); } } return(ResultEngineStatusMapper.MapFromBool(ok)); }
public async Task <ResultsEngineStatuses> Process(ITeamResultEngineContext context, IGameResults request, ResultsEngineResponse response) { var ok = true; RuleSetXRule rule = await context.GetRuleSpecification(Entities.Rule.Rules.SingleTeam); ITeamMatchModel match = await context.Fixture.GetMatch(request.MatchID); var statistics = await context.GetCompetitionPlayerGameStatistic(request, match); var allPlayers = context.GetAllPlayersWithTeam(request, match); foreach (var(playerID, team) in allPlayers) { var otherTeam = statistics.FirstOrDefault(x => x.PlayerID == playerID && x.Team.ID != team.ID); if (otherTeam != null) { var player = context.GetPreloadedPlayer(playerID); response.ValidationResult.Errors.Add(new ValidationFailure($"SingleTeamPlayer{playerID}", $"{player.DisplayName} has already played for and is tied to {otherTeam.Team.Name}.")); ok = false; } } return(ResultEngineStatusMapper.MapFromBool(ok)); }
public async Task <ResultsEngineStatuses> Process(ITeamResultEngineContext context, IGameResults request, ResultsEngineResponse response) { var ok = true; RuleSetXRule rule = await context.GetRuleSpecification(Entities.Rule.Rules.SingleTeam); ITeamMatchModel match = await context.Fixture.GetMatch(request.MatchID); var statistics = await context.GetCompetitionPlayerGameStatistic(request, match); var gameNumber = match.Data.TeamFixture.CompetitionRound.GameNumber; var allPlayers = context.GetAllPlayersWithTeam(request, match); foreach (var(playerID, team) in allPlayers) { if (statistics.Any(x => x.PlayerID == playerID && x.GameNumber == gameNumber)) { var player = context.GetPreloadedPlayer(playerID); response.ValidationResult.Errors.Add(new ValidationFailure($"SingleGamePerMatchGameNumber{playerID}", $"{player.DisplayName} has already played in game number {gameNumber}.")); ok = false; } } return(ResultEngineStatusMapper.MapFromBool(ok)); }
public async Task <ResultsEngineStatuses> Process(ITeamResultEngineContext context, IGameResults request, ResultsEngineResponse response) { var ok = true; RuleSetXRule rule = await context.GetRuleSpecification(Entities.Rule.Rules.CheckMaximumGamesForHigherRankedTeamPerCompetition); int maxGames = rule.DataInt1.Value; ITeamMatchModel match = await context.Fixture.GetMatch(request.MatchID); BowlsResults.Common.Domain.Entities.Team homeTeam = match.Data.Home; BowlsResults.Common.Domain.Entities.Team awayTeam = match.Data.Away; var statistics = await context.GetCompetitionPlayerGameStatistic(request, match); var teams = await this._competitionRepository.GetCompetitionTeams(context.Competition.ID); foreach (var gameResult in request.GameResults) { IEnumerable <int> homeIDs = GetHigherRankedTeamIDs(teams, homeTeam); IEnumerable <int> awayIDs = GetHigherRankedTeamIDs(teams, awayTeam); foreach (var playerID in gameResult.HomePlayers) { ok &= this.Validate(context, response, statistics, homeIDs, maxGames, playerID); } foreach (var playerID in gameResult.AwayPlayers) { ok &= this.Validate(context, response, statistics, awayIDs, maxGames, playerID); } } return(ResultEngineStatusMapper.MapFromBool(ok)); }
public async Task <ResultsEngineStatuses> Process(ITeamResultEngineContext context, IGameResults request, ResultsEngineResponse response) { var ok = true; RuleSetXRule rule = await context.GetRuleSpecification(Entities.Rule.Rules.SingleClub); ITeamMatchModel match = await context.Fixture.GetMatch(request.MatchID); var statistics = await context.GetCompetitionPlayerGameStatistic(request, match); var allPlayers = context.GetAllPlayersWithTeam(request, match); foreach (var(playerID, team) in allPlayers) { ok = this.Validate(context, response, statistics, playerID, team); } return(ResultEngineStatusMapper.MapFromBool(ok)); }
public List <Tuple <int, BowlsResults.Common.Domain.Entities.Team> > GetAllPlayersWithTeam(IGameResults gameResults, ITeamMatchModel matchModel) { if (this._gameResultPlayersWithTeam == null) { this._gameResultPlayersWithTeam = gameResults.GameResults.SelectAllPlayersWithTeam(matchModel.Data); } return(this._gameResultPlayersWithTeam); }
public async Task <ReadOnlyCollection <CompetitionPlayerGameStatistic> > GetCompetitionPlayerGameStatistic(IGameResults gameResults, ITeamMatchModel matchModel) { await this.LoadRuleSet(); if (this._competitionPlayerGameStatistics == null) { List <CompetitionPlayerGameStatistic> result = await this._competitionPlayerGameStatisticRepository.GetAllByCompetitionAndPlayer(this._ruleSet.Competitions.Select(x => x.CompetitionID), gameResults.GameResults.SelectMany(x => x.AllPlayers), matchModel.Data.Date); this._competitionPlayerGameStatistics = result.AsReadOnly(); } return(this._competitionPlayerGameStatistics); }