async private void menuItemDeleteAcct_Clicked(object sender, EventArgs e) { ObservableCollection <long> accounts; MenuItem m = sender as MenuItem; object account = m.CommandParameter as object; if (account != null) { BankCredential credential = this.BindingContext as BankCredential; bool answer = await DisplayAlert("Warning", "Are you sure you want like to delete " + account.ToString() + "?", "Yes", "No"); if (answer) { // update listviewAccounts UI accounts = JsonConvert.DeserializeObject <ObservableCollection <long> >(credential.Accounts); accounts.Remove(long.Parse(account.ToString())); credential.Accounts = JsonConvert.SerializeObject(accounts); listviewAccounts.ItemsSource = JsonConvert.DeserializeObject <ObservableCollection <long> >(credential.Accounts); } } else { await DisplayAlert("Delete Error", "Please enter a valid account number.", "OK"); } }
async private void menuItemDeleteQst_Clicked(object sender, EventArgs e) { KeyValuePair <string, string> pair = new KeyValuePair <string, string>(); if ((sender as MenuItem).CommandParameter is KeyValuePair <string, string> ) { pair = (KeyValuePair <string, string>)(sender as MenuItem).CommandParameter; BankCredential credential = this.BindingContext as BankCredential; bool answer = await DisplayAlert("Warning", "Are you sure you want like to delete \n'Q: " + pair.Key + " A: " + pair.Value + "'?", "Yes", "No"); if (answer) { // update listviewQuestions UI Dictionary <string, string> securityQuestions = JsonConvert.DeserializeObject <Dictionary <string, string> >(credential.SecurityQuestions); securityQuestions.Remove(pair.Key); credential.SecurityQuestions = JsonConvert.SerializeObject(securityQuestions); listviewQuestions.ItemsSource = JsonConvert.DeserializeObject <Dictionary <string, string> >(credential.SecurityQuestions); } } else { await DisplayAlert("Delete Error", "Please enter valid security question and answer.", "OK"); } }
public Task <int> SaveCredentialAsync(BankCredential credential) { //ID = 0 , default value >> new user if (credential.ID == 0) { return(_database.InsertAsync(credential)); } //Update user return(_database.UpdateAsync(credential)); }
async private void addModifyAccount(bool isAdd = true, string result = "") { BankCredential bc = this.BindingContext as BankCredential; int index = -1; ObservableCollection <long> accounts; if (bc.Accounts != null) { accounts = JsonConvert.DeserializeObject <ObservableCollection <long> >(bc.Accounts); } else { accounts = new ObservableCollection <long>(); } if (!isAdd) { index = accounts.IndexOf(long.Parse(result)); } result = await DisplayPromptAsync("Add Account", "Please enter new account number below (previous value: " + result + ")", keyboard : Keyboard.Numeric); if (long.TryParse(result, out long newAccount)) { if (isAdd) { accounts.Add(newAccount); } else { accounts[index] = newAccount; } bc.Accounts = JsonConvert.SerializeObject(accounts); listviewAccounts.ItemsSource = JsonConvert.DeserializeObject <ObservableCollection <long> >(bc.Accounts); } else { await DisplayAlert("Add Error", "Please enter valid account number.", "OK"); } }
async private void toolbarItemAdd_Clicked(object sender, EventArgs e) { Credential newCredential = newCredential = new Credential(); // create new credential string result = await DisplayActionSheet("Choose a credential type from the following:", "Cancel", null, Credential.credentialTypes); if (!string.IsNullOrWhiteSpace(result) && result.ToLower() != "cancel") { switch (result) { case "Default": break; case "Social Media": newCredential = new SocialMediaCredential(); break; case "Banking": newCredential = new BankCredential(); break; case "Wifi": newCredential = new WifiCredential(); break; default: await DisplayAlert("Error", "Invalid credential type", "ok"); break; } await Clipboard.SetTextAsync(string.Empty); searchBar.Text = string.Empty; await Navigation.PushAsync(new CredentialDetailPage(newCredential, _credentials)); } }