Inheritance: IModifiable, IGame
        private Square[] RepairMissingSquares(Game game, Square[] squares)
        {
            if (!squares.Any())
            {
                var missingSquares = new Board().Squares.SelectMany(s => s).ToArray();

                foreach (var square in missingSquares)
                {
                    square.Game = game;
                    square.ChessPiece = square.ChessPiece;
                    UnitOfWork.Add(square);
                }

                UnitOfWork.Commit();
                squares = missingSquares;
            }
            return squares;
        }
 private bool IsPlayersMove(Game game, ChessUser player)
 {
     var playerId = CurrentUser.Id;
     if (playerId == game.LightPlayer.Id && game.MoveCount % 2 == 0)
         return true;
     if (playerId == game.DarkPlayer.Id && game.MoveCount % 2 == 1)
         return true;
     return false;
 }
        private void RespondToChallenge(long challengeId, bool accepted)
        {
            var challenge = UnitOfWork.Find<Challenge>(challengeId);

            if (accepted)
            {
                var board = new Board();
                var squares = board.Squares.SelectMany(s => s);

                var game = new Game
                {
                    DarkPlayer = challenge.DarkPlayer,
                    LightPlayer = challenge.LightPlayer,
                    Name = challenge.Title,
                    Challenge = challenge,
                };

                foreach (var square in squares)
                {
                    square.Game = game;
                    square.ChessPiece = (ChessPiece) square.ChessPiece; //TODO: Why did I do this?
                    UnitOfWork.Add(square);
                }

                UnitOfWork.Add(game);
            }

            challenge.Accepted = accepted;
            UnitOfWork.Commit();
        }
        private GameModel GetGameModel(Game game)
        {
            var squares = game.Squares.ToArray();

            squares = RepairMissingSquares(game, squares);

            var moves = game.Moves.ToList();
            var board = new Board(squares);

            var boardModel = AutoMapper.Mapper.Map<BoardViewModel>(board);
            var darkPlayerModel = AutoMapper.Mapper.Map<PlayerViewModel>(game.DarkPlayer);
            var lightPlayerModel = AutoMapper.Mapper.Map<PlayerViewModel>(game.LightPlayer);
            var winnerPlayer = (PlayerViewModel)null;

            if (game.WinnerPlayer != null)
                winnerPlayer = AutoMapper.Mapper.Map<PlayerViewModel>(game.WinnerPlayer);

            var gameModel = new GameModel()
            {
                Board = boardModel,
                Name = game.Name,
                DarkScore = game.DarkScore,
                LightScore = game.LightScore,
                Id = game.Id,
                MoveCount = game.MoveCount,
                PlayerDark = darkPlayerModel,
                PlayerLight = lightPlayerModel,
                Moves = moves,
                IsCurrentPlayersMove = IsPlayersMove(game, CurrentUser),
                Complete = game.Complete,
                Winner = winnerPlayer,
            };

            return gameModel;
        }
 public GameManager(Game game)
 {
     Game = game;
     var squares = game.Squares.Select(s => s).ToArray();
     _board = new Board(squares);
 }