示例#1
0
        public async Task <Game> UpdateSpread(int GameId, SpreadUpdate spreadUpdates)
        {
            if (spreadUpdates == null)
            {
                throw new ArgumentException("No spreadUpdates parameter input for UpdateSpread (is null)");
            }

            using (var dbSession = _documentStore.LightweightSession())
            {
                var game = await dbSession
                           .Query <GameData>()
                           .Where(g => g.GameId == GameId)
                           .SingleOrDefaultAsync()
                           .ConfigureAwait(false);

                if (game == null)
                {
                    throw new ArgumentException($"No matching game found to update for Game Id: {GameId}");
                }

                GameChanger gameChanger = new GameChanger(game, dbSession);
                gameChanger.ApplySpread(spreadUpdates);
                dbSession.Store(game);
                dbSession.SaveChanges();

                var pickemEvent = new PickemSystemEvent(PickemSystemEventTypes.SpreadUpdated, GameId);
                _pickemEventer.Emit(pickemEvent);
            }

            // read back out to return
            return(await this.ReadGame(GameId));
        }
示例#2
0
        internal async Task <Game> LockSpread(int gameId)
        {
            using (var dbSession = _documentStore.LightweightSession())
            {
                var game = await dbSession
                           .Query <GameData>()
                           .Where(g => g.GameId == gameId)
                           .SingleOrDefaultAsync()
                           .ConfigureAwait(false);

                if (game == null)
                {
                    throw new ArgumentException($"No matching game found to update for Game Id: {gameId}");
                }

                GameChanger gameChanger = new GameChanger(game, dbSession);
                gameChanger.LockSpread();
                dbSession.Store(game);
                dbSession.SaveChanges();

                var pickemEvent = new PickemSystemEvent(PickemSystemEventTypes.SpreadLocked, gameId);
                _pickemEventer.Emit(pickemEvent);
            }

            // read back out to return
            return(await this.ReadGame(gameId));
        }
示例#3
0
        public async Task <Game> UpdateGame(int GameId, GameUpdate gameUpdates)
        {
            if (gameUpdates == null)
            {
                throw new ArgumentException("No gameUpdates parameter input for UpdateGame (is null)");
            }

            using (var dbSession = _documentStore.LightweightSession())
            {
                var game = await dbSession
                           .Query <GameData>()
                           .Where(g => g.GameId == GameId)
                           .SingleOrDefaultAsync()
                           .ConfigureAwait(false);

                if (game == null)
                {
                    throw new ArgumentException($"No matching game found for Game Id: {GameId}");
                }

                GameChanger gameChanger = new GameChanger(game, dbSession);
                var         gameChanges = gameChanger.ApplyChanges(gameUpdates);
                dbSession.Store(game);

                var leagueCodesAffected = new List <string>();

                if (gameChanges.GameStateChanged || gameChanges.ScoreChanged)
                {
                    // score and/or game state changed, let all the leagues know.

                    // TODO - avoid direct new up of league service. Cannot IoC due to circlies because game service uses league. What to do?
                    var leagueService = _serviceProvider.GetService <LeagueService>();
                    var leaguesData   = leagueService.ApplyGameChanges(game, gameChanges, dbSession);

                    foreach (var leagueData in leaguesData)
                    {
                        dbSession.Store(leagueData);
                        leagueCodesAffected.Add(leagueData.LeagueCode);
                    }
                }

                dbSession.SaveChanges();

                if (gameChanges.GameChanged)
                {
                    var pickemEvent = new PickemSystemEvent(PickemSystemEventTypes.GameChanged, GameId);
                    pickemEvent.DynamicInformation.ancillaryMetaDataChanged = gameChanges.AncillaryMetaDataChanged;
                    pickemEvent.DynamicInformation.gameStateChanged         = gameChanges.GameStateChanged;
                    pickemEvent.DynamicInformation.scoreChanged             = gameChanges.ScoreChanged;

                    foreach (var leagueCode in leagueCodesAffected)
                    {
                        pickemEvent.LeagueCodesAffected.Add(leagueCode);
                    }

                    _pickemEventer.Emit(pickemEvent);
                }
            }

            // read back out to return
            return(await this.ReadGame(GameId));
        }