Пример #1
0
        public async Task <int> SaveBoardToDatabaseAsync(StringBuilder sb, int gameId, int generation)
        {
            if (!_isConnected)
            {
                return(0);
            }

            int changes    = 0;
            var gridString = sb.ToString();

            using (var db = new BoardDataContext())
            {
                BoardEntity bg = new BoardEntity
                {
                    GameId     = gameId,
                    Generation = generation,
                    Grid       = gridString
                };

                db.BoardGrid.Add(bg);

                changes = await db.SaveChangesAsync();
            }
            return(changes);
        }
Пример #2
0
        public async Task <int> SaveGameToDatabaseAsync(GameEntity game)
        {
            if (!_isConnected)
            {
                return(0);
            }

            int changes = 0;

            using (var db = new BoardDataContext())
            {
                db.SavedGames.Add(game);
                changes = await db.SaveChangesAsync();
            }
            return(changes);
        }
Пример #3
0
        public async Task <int> DeleteSaveGameAsync(GameEntity game)
        {
            if (!_isConnected)
            {
                return(0);
            }

            int changes = 0;

            using (var db = new BoardDataContext())
            {
                var sgd            = db.SavedGames.Where(x => x.Id == game.Id).FirstOrDefault();
                var boardsToDelete = db.BoardGrid.Where(x => x.GameId == sgd.BoardGridGameID);

                db.BoardGrid.RemoveRange(boardsToDelete);
                db.SavedGames.Remove(sgd);

                changes = await db.SaveChangesAsync();
            }

            return(changes);
        }