/// <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; }
/// <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; }
static void Main(string[] args) { DAL conn = new DAL(); Console.WriteLine("starting tests:"); //testConn(conn); //conn.AddUser("john2", "pass", 1000); //conn.AddUser("john", "pass", 1000); //testConn(conn); Game g = conn.GetGame("153"); User u = conn.GetUser("john"); u.money = 5000; Console.WriteLine("lucky users is ID:" + u.ID + " username:"******" password:"******" money:" + u.money); //conn.UpdateDB(u); testConn(conn); Console.WriteLine("delete tests"); //conn.deleteAllUsers(); //conn.deleteAllGames(); Console.WriteLine("end"); }
/// <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; }
/// <summary> /// Get specific user /// </summary> /// <param name="username"></param> /// <returns></returns> public UserWcf getUser(string username) { DAL dal = new DAL(); User user = dal.GetUser(username); if (user != null) return userToWCF(user); return null; }