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 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.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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }