public void RemoveAccount(int payload) { var toDelete = UserAccounts.FindLast(acc => acc.AccountId == payload); LocalContext.RemoveAccount(toDelete); UserAccounts.RemoveAll(account => account.AccountId == toDelete.AccountId); }
private void RemoveAccount_Executed(object sender, ExecutedRoutedEventArgs e) { var a = e.Parameter as Account; if (MessageBox.Show($"Are you sure you want to remove '{a.Email}' on '{a.ServerName}' from this machine?", "Remove account?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { if (a.IsDefault) { ClearDefaultAccount(null, null); } LocalContext.RemoveAccount(a); accounts.Remove(a); } }
public void SaveOrUpdateAccount(Account newAccount) { var existingAccounts = LocalContext.GetAllAccounts(); var newUri = new Uri(newAccount.RestApi); var serverName = GetServerName(newUri); foreach (var acc in existingAccounts) { var eUri = new Uri(acc.RestApi); if ((eUri.Host == newUri.Host) && (acc.Email == newAccount.Email) && (eUri.Port == newUri.Port)) { acc.ServerName = serverName; acc.Token = newAccount.Token; LocalContext.RemoveAccount(acc); // TODO: Add update account method, as this is rather stupid LocalContext.AddAccount(acc); return; } } newAccount.ServerName = serverName; LocalContext.AddAccount(newAccount); }