Ejemplo n.º 1
0
        public void TestUsersMethods()
        {
            using (DataContextDataContext dc = new DataContextDataContext())
              {
            User usr1 = DBDataManager.GetUserByLogin("testuser1");
            User usr2 = DBDataManager.GetUserByLogin("testuser2");
            if (usr1 != null) dc.Users.DeleteOnSubmit(dc.Users.First(u => u.Id == usr1.Id));
            if (usr2 != null) dc.Users.DeleteOnSubmit(dc.Users.First(u => u.Id == usr2.Id));
            dc.SubmitChanges();

            Assert.IsTrue(DBDataManager.CreateUser("testuser1", "123", "name1", "*****@*****.**"));
            Assert.IsFalse(DBDataManager.CreateUser("testuser1", "123", "name1", "*****@*****.**"));
            Assert.IsTrue(DBDataManager.CreateUser("testuser2", "123", "name2", "*****@*****.**"));
            usr1 = DBDataManager.GetUserByLogin("testuser1");
            usr2 = DBDataManager.GetUserByLogin("testuser2");
            Assert.IsTrue(usr1 != null && usr2 != null);
              }
        }
Ejemplo n.º 2
0
 public static int CreateGame(int bId, int wId)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     Game dbGame = new Game();
     dbGame.BlackUserId = bId;
     dbGame.WhiteUserId = wId;
     GameObject cGameObject = new GameObject();
     dbGame.GameData = Serialize(cGameObject.GetState());
     dc.Games.InsertOnSubmit(dbGame);
     dc.SubmitChanges();
     return dbGame.Id;
       }
     }
     catch (Exception)
     {
       return 0;
     }
 }
Ejemplo n.º 3
0
 public static bool CreateUser(string login, string pass, string name, string email)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     User u = new User()
       {
         Email = email,
         Login = login,
         Name = login,
         Password = ChessCore.Utils.CalculateMD5Hash(pass)
       };
     dc.Users.InsertOnSubmit(u);
     dc.SubmitChanges();
       }
       return true;
     }
     catch (Exception)
     {
       return false;
     }
 }
Ejemplo n.º 4
0
 public static User GetUserById(int id)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     User user = dc.Users.Where(u => u.Id == id).FirstOrDefault();
     return user;
       }
     }
     catch (Exception)
     {
       return null;
     }
 }
Ejemplo n.º 5
0
 public static User GetUserByEmail(string email)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     User user = dc.Users.Where(u => u.Email == email).FirstOrDefault();
     return user;
       }
     }
     catch (Exception)
     {
       return null;
     }
 }
Ejemplo n.º 6
0
 public static bool UpdateGame(ChessCore.GameObject gs)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     var data = (from G in dc.Games
                 where G.Id == gs.gameId
                 select G).FirstOrDefault();
     if (data == null) return false;
     data.GameData = Serialize(gs);
     data.GameStatus = (int) gs.status;
     dc.SubmitChanges();
       }
       return true;
     }
     catch (Exception)
     {
       return false;
     }
 }
Ejemplo n.º 7
0
 public static void RemoveUser(User usr)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     dc.Users.DeleteOnSubmit(usr);
     dc.SubmitChanges();
       }
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 8
0
 public static GameObject LoadGameById(int gId)
 {
     try
     {
       GameState GameState;
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     Game dbGame = dc.Games.FirstOrDefault(g => g.Id == gId);
     if (dbGame == null)
       return null;
     GameState = (GameState)Deserialize(dbGame);
       }
       GameObject GameObject = null;
       return GameObject;
     }
     catch (Exception)
     {
       return null;
     }
 }
Ejemplo n.º 9
0
 public static User GetUserByLogin(string login)
 {
     try
     {
       using (DataContextDataContext dc = new DataContextDataContext())
       {
     User user = dc.Users.Where(u => u.Login == login).FirstOrDefault();
     return user;
       }
     }
     catch (Exception)
     {
       return null;
     }
 }
Ejemplo n.º 10
0
 public void TestLoadGame()
 {
     using (DataContextDataContext dc = new DataContextDataContext())
       {
     int gameID = DBDataManager.CreateGame(7, 9);
     GameObject gameObject = DBDataManager.LoadGameById(gameID);
       }
 }
Ejemplo n.º 11
0
        public void TestCreateGame()
        {
            using (DataContextDataContext dc = new DataContextDataContext())
              {
            User usr1 = DBDataManager.GetUserByLogin("testuser1");
            User usr2 = DBDataManager.GetUserByLogin("testuser2");
            if (usr1 == null || usr2 == null)
            {
              Assert.IsTrue(DBDataManager.CreateUser("testuser1", "123", "name1", "*****@*****.**"));
              Assert.IsTrue(DBDataManager.CreateUser("testuser2", "123", "name2", "*****@*****.**"));
              usr1 = DBDataManager.GetUserByLogin("testuser1");
              usr2 = DBDataManager.GetUserByLogin("testuser2");
            }

            Assert.IsTrue(DBDataManager.CreateGame(usr1.Id, usr2.Id) != 0);
              }
        }