예제 #1
0
        public Game EditGame(User ownerPlayer, GameResultId gameResultId, Game newData)
        {
            Game game = _chessHubDbContext.Games.FirstOrDefault(game =>
                                                                game.OwnerPlayer.Equals(ownerPlayer) && game.GameResultId.Equals(gameResultId));

            _chessHubDbContext.Games.Remove(game);
            _chessHubDbContext.SaveChanges();


            _chessHubDbContext.Games.Add(newData);
            _chessHubDbContext.SaveChanges();
            var games = _chessHubDbContext.Games.Include(x => x.OwnerPlayer).ToList();

            return(newData);
        }
예제 #2
0
        public GameDto EditGame(UserDto ownerPlayer, GameResultId GameResult, GameDto newData)
        {
            Game newEntityData = _mapper.Map <Game>(newData);
            User OwnerPlayer   = _userRepository.GetUser(newEntityData.OwnerPlayer.Email);
            User BlackPlayer   = _userRepository.GetUser(newEntityData.BlackPlayer.Email);
            User WhitePlayer   = _userRepository.GetUser(newEntityData.WhitePlayer.Email);

            newEntityData.OwnerPlayer = OwnerPlayer;
            newEntityData.BlackPlayer = BlackPlayer;
            newEntityData.WhitePlayer = WhitePlayer;
            newEntityData.StartTime   = DateTime.Now;
            try
            {
                Game editedGame = _gameRepository.EditGame(newEntityData.OwnerPlayer, GameResult, newEntityData);
                return(_mapper.Map <GameDto>(editedGame));
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }