コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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;
        }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
        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;
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 public GameBDO UpdateGame(GameBDO gameToUpdate)
 {
     return _gameRepository.UpdateGame(gameToUpdate);
 }
コード例 #7
0
 public GameBDO AddGame(GameBDO gameToCreate)
 {
     return _gameRepository.AddGame(gameToCreate);
 }
コード例 #8
0
 private bool CheckIfPlayerVerifiedGame(GameBDO game, string playerLogin)
 {
     if ((game.PlayerOneLogin == playerLogin && game.PlayerOneConfirmed) || (game.PlayerTwoLogin == playerLogin && game.PlayerTwoConfirmed))
     {
         return true;
     }
     return false;
 }
コード例 #9
0
 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();
 }