Esempio n. 1
0
        public static void InsertDataToDb(GameEngine.GameBoard board, string boardName)
        {
            using var ctx = new AppDbContext();

            // Create GameBoard model
            var gameBoardModel = new GameBoard()
            {
                BoardName  = boardName,
                JsonString = JsonConvert.SerializeObject(board)
            };

            // Insert GameBoard model and save changes
            ctx.GameBoards.Add(gameBoardModel);
            ctx.SaveChanges();
        }
Esempio n. 2
0
        public static GameEngine.GameBoard LoadDataFromDb(int boardId)
        {
            using var ctx = new AppDbContext();
            var gameBoard = new GameEngine.GameBoard();

            foreach (var board in ctx.GameBoards)
            {
                if (board.GameBoardId == boardId)
                {
                    gameBoard = JsonConvert.DeserializeObject <GameEngine.GameBoard>(board.JsonString);
                }
            }

            return(gameBoard);
        }