Esempio n. 1
0
 private static bool CheckIfTheNameIsInTheDataBase(string nameOfTheSavedGame)
 {
     using (CheckersDBEntities db = new CheckersDBEntities())
     {
         try
         {
             var name = db.GameManagments.Where(g => g.Name == nameOfTheSavedGame).First();
             return(true);
         }
         catch { }
     }
     return(false);
 }
Esempio n. 2
0
        public static Guid GetData(string nameOfTheSavedGame)
        {
            using (CheckersDBEntities db = new CheckersDBEntities())
            {
                try
                {
                    var gameId = db.GameManagments.Where(g => g.Name == nameOfTheSavedGame).First().GameId;

                    return(gameId);
                }
                catch { }
            }
            return(Guid.Empty);
        }
Esempio n. 3
0
        public static List <BoardTile> GetData(Guid gameId)
        {
            using (CheckersDBEntities db = new CheckersDBEntities())
            {
                try
                {
                    var boardTiles = db.BoardTiles.Where(b => b.GameId == gameId);

                    if (boardTiles.Any() == false)
                    {
                        return(new List <BoardTile>());
                    }

                    return(boardTiles.ToList());
                }
                catch
                { }
            }
            return(new List <BoardTile>());
        }
Esempio n. 4
0
        public static Guid InsertData(string nameOfTheSavedGame, int CurrentTurn)
        {
            Guid gameId = new Guid();

            using (CheckersDBEntities db = new CheckersDBEntities())
            {
                try
                {
                    if (CheckIfTheNameIsInTheDataBase(nameOfTheSavedGame))
                    {
                        gameId = db.GameManagments.Where(g => g.Name == nameOfTheSavedGame).First().GameId;
                        db.GameManagments.Where(g => g.Name == nameOfTheSavedGame).First().CurrentColorTurn = CurrentTurn;
                    }

                    else
                    {
                        gameId = Guid.NewGuid();
                        GameManagment newGame = new GameManagment()
                        {
                            Name             = nameOfTheSavedGame,
                            CurrentColorTurn = CurrentTurn,
                            GameId           = gameId
                        };
                        db.GameManagments.Add(newGame);
                    }

                    db.SaveChanges();

                    return(gameId);
                }
                catch
                {
                    return(Guid.Empty);
                }
            }
        }
Esempio n. 5
0
        private static bool DeleteData(Guid gameId)
        {
            using (CheckersDBEntities db = new CheckersDBEntities())
            {
                try
                {
                    var query = from Tiles in db.BoardTiles
                                where Tiles.GameId == gameId
                                select Tiles;

                    foreach (var tile in query)
                    {
                        db.BoardTiles.Remove(tile);
                    }

                    db.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 6
0
        public static bool InsertData(List <BoardTile> boardTiles)
        {
            if (DeleteData(boardTiles[0].GameId) == false)
            {
                return(false);
            }

            using (CheckersDBEntities db = new CheckersDBEntities())
            {
                try
                {
                    foreach (var tile in boardTiles)
                    {
                        db.BoardTiles.Add(tile);
                        db.SaveChanges();
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }