Beispiel #1
0
 public void addUser(User user) 
 {
     int number = MobilisDatabase.getDatabase().Table<User>().Count();
     if (number == 0)
     {
         MobilisDatabase.getDatabase().Insert(user);
     }
     else 
     {
         MobilisDatabase.getDatabase().Update(user);
     }
 }
 public void submitLoginData(string name, string password) 
 {
         loginService.getToken(Constants.tokenURL, name, password, r =>
         {
             if (r.hasError())
             {
                 ServiceLocator.Messenger.Publish<BaseViewMessage>(new BaseViewMessage(this, new Message(BaseViewMessage.MessageTypes.CONNECTION_ERROR)));
             }
             else
             {
                 var enumerator = r.Value.GetEnumerator();
                 enumerator.MoveNext();
                 string token = enumerator.Current;
                 try
                 {
                     // atualiza o token do usuário
                     User user = userDao.getUser();
                     user.token = token;
                     userDao.addUser(user);
                 }
                 catch (Exception e)
                 {
                     // cria usuário novo
                     User user = new User();
                     user.token = token;
                     user._id = 1;
                     user.autoLogin = true;
                     userDao.addUser(user);
                 }
                 finally
                 {
                     ServiceLocator.Messenger.Publish<BaseViewMessage>(new BaseViewMessage(this, new Message(BaseViewMessage.MessageTypes.LOGIN_CONNECTION_OK)));
                 }
             }
         });
     }