public bool register(User u)
 {
     try
     {
         user = new User() { Username = u.Username, Role = u.Role };
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
 public bool registerUserRoom(UserGameRoom ugr)
 {
     try
     {
         user = new User() { Username = ugr.user.Username, Id = ugr.user.Id, Role = ugr.user.Role };
         gameRoom = new GameRoom() {Id = ugr.gameRoom.Id, Date = ugr.gameRoom.Date, Name = ugr.gameRoom.Name, PainterId = ugr.gameRoom.PainterId, Users = ugr.gameRoom.Users };
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
 public bool addNewPlayer(User user, GameRoom gameroom)
 {
     try
     {
         foreach (var gr in gameRooms)
             if (gr.Id == gameroom.Id)
             {
                 gr.Users.Add(user);
                 break;
             }
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
        public bool addUser(User user)
        {
            try
            {
                if (getUser(user) != null)
                    return false;
                else
                {
                    User u = new User() { Username = user.Username, Password = user.Password, Role = "User" };
                    ServerContext.Instance.databaseContext.Users.Add(u);

                    ServerContext.Instance.databaseContext.SaveChanges();

                    return true;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }
        public bool addUser(User user)
        {
            using (DatabaseContext db = new DatabaseContext())
            {
                try
                {
                    if (getUser(user) != null)
                        return false;
                    else
                    {
                        User u = new User() { Username = user.Username, Password = user.Password, Role = "User" };
                        db.Users.Add(u);

                        db.SaveChanges();

                        return true;
                    }
                }
                catch (Exception e)
                {
                    return false;
                }
            }
        }
        public bool addNewRoom(string name, User user)
        {
            try
            {
                GameRoom gr = new GameRoom() { Id = idGenerator.Next(), Name = name, Date = DateTime.Now, PainterId = user.Id };
                gr.Users = new List<User>();
                gr.Users.Add(user);

                gameRooms.Add(gr);

                return true;
            }
            catch(Exception e)
            {
                return false;
            }
        }
 public User getUser(User user)
 {
     try
     {
         var us = (from u in ServerContext.Instance.databaseContext.Users
                   where u.Username == user.Username && u.Password == user.Password
                   select u);
         if (us.Count() != 1)
             return null;
         else
             return us.First();
     }
     catch (Exception e)
     {
         return null;
     }
 }
 public User getUser(User user)
 {
     using (DatabaseContext db = new DatabaseContext())
     {
         try
         {
             var us = (from u in db.Users
                      where u.Username == user.Username && u.Password == user.Password
                      select u);
             if (us.Count() != 1)
                 return null;
             else
                 return us.First();
         }
         catch (Exception e)
         {
             return null;
         }
     }
 }