public GameBDO UpdateGame(GameBDO gameToUpdate)
 {
     try
     {
         using (var context = _contextFactory.Create())
         {
             var gameEntity = context.Games.SingleOrDefault(g => g.Id == gameToUpdate.Id);
             if (gameEntity != null)
             {
                 gameEntity.PlayerOneConfirmed = gameToUpdate.PlayerOneConfirmed;
                 gameEntity.PlayerTwoConfirmed = gameToUpdate.PlayerTwoConfirmed;
                 gameEntity.GameDate = gameToUpdate.GameDate;
                 gameEntity.PlayerOneLogin = gameToUpdate.PlayerOneLogin;
                 gameEntity.PlayerTwoLogin = gameToUpdate.PlayerTwoLogin;
                 gameEntity.PlayerOneScore = gameToUpdate.PlayerOneScore;
                 gameEntity.PlayerTwoScore = gameToUpdate.PlayerTwoScore;
                 context.SaveChanges();
                 return gameEntity.MapToDomainObject();
             }
             throw new ArgumentException("Game not found.");
         }
     }
     catch (Exception exception)
     {
         throw new ArgumentException("Game was not found.", exception.InnerException);
     }
 }
        public GameBDO AddGame(GameBDO gameToCreate)
        {
            var tournament = _tournamentRepository.GetTournament(gameToCreate.TournamentId);
            if (tournament == null)
            {
                throw new Exception(string.Format("Tournament with ID: {0} was not found.", gameToCreate.TournamentId));
            }

            gameToCreate.Id = _games.Max(g => g.Id) + 1;

            return gameToCreate;
        }
 public HttpResponseMessage UpdateGame(GameBDO gameToUpdate)
 {
     try
     {
         var result = _gamesProvider.UpdateGame(gameToUpdate);
         return Request.CreateResponse(HttpStatusCode.OK, result);
     }
     catch (Exception exception)
     {
         throw new ArgumentException("Failed to update game.", exception.InnerException);
     }
 }
        public GameBDO UpdateGame(GameBDO gameToUpdate)
        {
            var existingGame = _games.SingleOrDefault(g => g.Id == gameToUpdate.Id);
            if (existingGame == null)
            {
                throw new Exception(string.Format("Game with ID: {0} does not exist. Update failed.", gameToUpdate.Id));
            }

            var existingGameIndex = _games.IndexOf(existingGame);
            _games[existingGameIndex] = gameToUpdate;

            return gameToUpdate;
        }
 public GameBDO AddGame(GameBDO gameToCreate)
 {
     try
     {
         using (var context = _contextFactory.Create())
         {
             var gameEntity = gameToCreate.MapToEntity();
             var result = context.Games.Add(gameEntity);
             context.SaveChanges();
             return gameToCreate;
         }
     }
     catch (Exception exception)
     {
         throw new ArgumentException("Failed to create a game.", exception.InnerException);
     }
 }
 public GameBDO UpdateGame(GameBDO gameToUpdate)
 {
     return _gameRepository.UpdateGame(gameToUpdate);
 }
 public GameBDO AddGame(GameBDO gameToCreate)
 {
     return _gameRepository.AddGame(gameToCreate);
 }
 private bool CheckIfPlayerVerifiedGame(GameBDO game, string playerLogin)
 {
     if ((game.PlayerOneLogin == playerLogin && game.PlayerOneConfirmed) || (game.PlayerTwoLogin == playerLogin && game.PlayerTwoConfirmed))
     {
         return true;
     }
     return false;
 }
 private StatusBDO GetNotificationStatus(GameBDO game)
 {
     if (game.PlayerOneConfirmed && game.PlayerTwoConfirmed)
     {
         return new StatusBDO
         {
             Id = 1,
             NotificationClass = "list-group-item-success"
         };
     }
     if (game.PlayerOneConfirmed == false && game.PlayerTwoConfirmed == false)
     {
         return new StatusBDO
         {
             Id = 3,
             NotificationClass = "list-group-item-danger"
         };
     }
     if (game.PlayerOneConfirmed || game.PlayerTwoConfirmed)
     {
         return new StatusBDO
         {
             Id = 2,
             NotificationClass = "list-group-item-warning"
         };
     }
     return new StatusBDO();
 }