public async Task <String> GetUserID(AccountItem item, string randomusername) { try { if (Reachability.HasInternetConnection()) { var accounts = (await GetAccountsAsync()).ToArray(); for (int i = 0; i < accounts.Length; i++) { if (string.Equals(randomusername, accounts[i].username)) { return(accounts[i].ID); } } } } catch (WebException) { Console.WriteLine("UserDialog here, no net connection"); //user dialog //UserDialogs.Instance.WarnToast ("Your data connection is a bit slow right now", null, 2000); } catch (TaskCanceledException) { //UserDialogs.Instance.WarnToast ("Your data connection is a bit slow right now", null, 2000); } return(string.Empty); }
public async Task <String> CreateNewAccount() { Console.WriteLine("Creating new account"); Random random = new Random(); var randomusernamenumber = random.Next(); var randomusername = randomusernamenumber.ToString(); var user = new AccountItem { password = Values.DEFAULTPASSWORD, username = randomusername }; await SaveAccountTaskAsync(user); Console.WriteLine("New account created"); return(await GetUserID(user, randomusername)); }
public async Task <bool> SaveAccountTaskAsync(AccountItem item) { try { if (Reachability.HasInternetConnection()) { if (item.ID == null) { await accountsTable.InsertAsync(item); } else { await accountsTable.UpdateAsync(item); } return(true); } } catch (Exception e) { Console.WriteLine("New account Save error: " + e.Message); } return(false); }