Exemple #1
0
        public Task <Entities.Game.Game> Update <TMatchGame, TMatch, TContext>(IMatchModel <TMatchGame, TMatch, TContext> matchModel, GameResult gameResult)
            where TMatchGame : MatchXGame
            where TMatch : Match
            where TContext : IResultsEngineContext
        {
            if (matchModel == null)
            {
                throw new ArgumentNullException(nameof(matchModel));
            }
            if (gameResult == null)
            {
                throw new ArgumentNullException(nameof(gameResult));
            }

            var matchConfiguration = matchModel.Data.MatchFormat.GetVariationByID(gameResult.MatchFormatXGameVariationID);

            if (matchConfiguration == null)
            {
                throw new ArgumentNullException(nameof(matchConfiguration));
            }

            if (matchConfiguration.GameVariation.GameFormatID != GameFormats.Singles)
            {
                throw new InvalidOperationException("Wrong Game Format for Service");
            }

            return(this.InnerUpdate(matchModel, gameResult));
        }
Exemple #2
0
 protected abstract Task <Entities.Game.Game> InnerUpdate <TMatchGame, TMatch, TContext>(IMatchModel <TMatchGame, TMatch, TContext> matchModel, GameResult gameResult)
     where TMatchGame : MatchXGame
     where TMatch : Match
     where TContext : IResultsEngineContext;
        protected override async Task <Entities.Game.Game> InnerUpdate <TMatchGame, TMatch, TContext>(IMatchModel <TMatchGame, TMatch, TContext> matchModel, GameResult gameResult)
        {
            var matchConfiguration = matchModel.Data.MatchFormat.GetVariationByID(gameResult.MatchFormatXGameVariationID);
            var playerGame         = matchModel.GetGame(gameResult.MatchFormatXGameVariationID);
            var gameData           = playerGame.Game as FoursomesGame;

            if (gameData == null)
            {
                throw new ArgumentNullException(nameof(gameData));
            }

            if (gameResult.VoidGame)
            {
                Player voidPlayer = await this._playerRepository.Get(-7);

                this.SetVoidGameValues(gameData, gameResult, matchConfiguration);

                gameData.AddHomePlayer(voidPlayer);
                gameData.AddHomePlayer(voidPlayer);
                gameData.AddHomePlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
            }
            else
            {
                this.GuardCheckPlayerCounts(gameResult);
                IList <Player> homePlayers = await this.GetPlayers(gameResult.HomePlayers);

                IList <Player> awayPlayers = await this.GetPlayers(gameResult.AwayPlayers);

                IEnumerable <Player> loadedPlayers = homePlayers.Concat(awayPlayers).ToList();

                this.GuardCheckLoadedPlayerCounts(loadedPlayers);
                this.GuardCheckLoadedPlayerGenders(loadedPlayers, matchConfiguration);

                this.SetCommonGameValues(gameData, gameResult, matchConfiguration);

                foreach (Player player in homePlayers)
                {
                    gameData.AddHomePlayer(player);
                }
                foreach (Player player in awayPlayers)
                {
                    gameData.AddAwayPlayer(player);
                }
            }


            gameData.SetAuditFields();

            return(gameData);
        }
        protected override async Task <Entities.Game.Game> InnerCreate <TMatchGame, TMatch, TContext>(IMatchModel <TMatchGame, TMatch, TContext> matchModel, GameResult gameResult)
        {
            var matchConfiguration = matchModel.Data.MatchFormat.GetVariationByID(gameResult.MatchFormatXGameVariationID);
            var gameData           = new FoursomesGame();

            gameData.AssociationID = matchModel.Context.Competition.AssociationID;
            gameData.SeasonID      = matchModel.Context.Competition.Season.ID;
            gameData.Date          = matchModel.Data.Date;
            gameData.VenueTypeID   = matchModel.Data.VenueTypeID;
            gameData.Pitch         = matchModel.Data.Pitch;

            if (gameResult.VoidGame)
            {
                Player voidPlayer = await this._playerRepository.Get(-7);

                this.SetVoidGameValues(gameData, gameResult, matchConfiguration);

                gameData.AddHomePlayer(voidPlayer);
                gameData.AddHomePlayer(voidPlayer);
                gameData.AddHomePlayer(voidPlayer);
                gameData.AddHomePlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
                gameData.AddAwayPlayer(voidPlayer);
            }
            else
            {
                this.GuardCheckPlayerCounts(gameResult);

                IList <Player> homePlayers = await this.GetPlayers(gameResult.HomePlayers);

                IList <Player> awayPlayers = await this.GetPlayers(gameResult.AwayPlayers);

                var loadedPlayers = homePlayers.Concat(awayPlayers);

                this.GuardCheckLoadedPlayerCounts(loadedPlayers);
                this.GuardCheckLoadedPlayerGenders(loadedPlayers, matchConfiguration);

                this.SetCommonGameValues(gameData, gameResult, matchConfiguration);

                foreach (Player player in homePlayers)
                {
                    gameData.AddHomePlayer(player);
                }
                foreach (Player player in awayPlayers)
                {
                    gameData.AddAwayPlayer(player);
                }
            }

            gameData.SetAuditFields();

            return(gameData);
        }