Esempio n. 1
0
 /// <summary>
 /// Logout is only called when leaving the application
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool logout(UserWcf user)
 {
     RemoveGameByUser(user);
     updateUser(user);
     // other cleanups can come here
     return true;
 }
Esempio n. 2
0
 /// <summary>
 /// Add a new Game to DB using the Wcf Service
 /// </summary>
 /// <param name="IP"></param>
 /// <param name="user"></param>
 public void addGame(String IP, UserWcf user)
 {
     DAL dal = new DAL();
     Game game = dal.AddGame(IP, user.Username);
     WcfServiceCallback update = OperationContext.Current.GetCallbackChannel<WcfServiceCallback>();
     update.updateGames("add",gameToWCF(game));
 }
Esempio n. 3
0
 /// <summary>
 /// Updated the user in the DB using the UserWcf Repreansanataion 
 /// </summary>
 /// <param name="u"></param>
 /// <returns></returns>
 public bool updateUser(UserWcf u)
 {
     DAL dal = new DAL();
     User dbUser = dal.GetUser(u.ID);
     if (dbUser != null)
     {
         dbUser.money = u.money;
         dbUser.numOfGames = u.numOfGames;
         dal.UpdateDB(dbUser);
         return true; // again no exception handling
     }
     return false; // should handle exception better;
 }
Esempio n. 4
0
 /// <summary>
 /// login without a callback
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns>UserWcf object with the correct user or null if the authentication was unsuccessfull</returns>
  public UserWcf loginWeb(string username, string password)
  {
      DAL dal = new DAL();
      User u = dal.GetUser(username); //verify that there is such a user
      if (u != null && u.password == password) // verify the password
      {
          UserWcf user = new UserWcf();
          user.ID = u.ID;
          user.Username = u.username;
          user.money = u.money;
          if (u.numOfGames != null)
              user.numOfGames = (int)u.numOfGames; // somehow this became in? instead of int
          user.isAdmin = u.isAdmin;
          return user;
      }
      return null;
  }
Esempio n. 5
0
 /// <summary>
 /// Remove game of a user
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool RemoveGameByUser(UserWcf user) 
 {
     DAL dal = new DAL();
     User dbUser = dal.GetUser(user.ID);
     if (dbUser != null)
     {
         Game game = dal.GetGame(dbUser);
         if(game != null)
         {
             dal.removeGame(game);
             return true;
         }
     }
     return false;
 }
Esempio n. 6
0
 /// <summary>
 /// Convert a WCF user to User entity
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 private User WCFtoUser(UserWcf user)
 {
     User ret = new User();
     ret.ID = user.ID;
     ret.username = user.Username;
     ret.money = user.money;
     if (user.numOfGames != null)
         ret.numOfGames = (int)user.numOfGames;
     ret.isAdmin = user.isAdmin;
     return ret;
 }
Esempio n. 7
0
 /// <summary>
 /// Creating a new user in DB 
 /// not very secure
 /// </summary>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public bool addUser(UserWcf user,string password)
 {
     DAL dal = new DAL();
     dal.AddUser(user.Username, password);
     return true;
 }
Esempio n. 8
0
 public Player(UserWcf u)
 {
     this.ID = u.ID;
     this.Username = u.Username;
     this.money = u.money;
 }