private async void Import() { AllowInput = false; try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "JSON|*.json"; ofd.DefaultExt = "json"; if (ofd.ShowDialog() == true && ofd.CheckFileExists && ofd.CheckPathExists) { var imported = FileExporter.FileExporter.ImportTransactionType(ofd.FileName); IDatabaseService dbconn = new DatabaseService(); dbconn.ConnectionString = ConnectionStringsProvider.Get(); foreach (var entry in imported) { if (!TransactionTypes.Any(c => c.Name == entry.Name)) { entry.Id = 0; await dbconn.TransactionTypeService.SaveAsync(entry); } } var transactionTypesRaw = await dbconn.TransactionTypeService.GetTransactionTypesAsync(); TransactionTypes = new ObservableCollection <ITransactionType>(transactionTypesRaw); TransactionType = null; ReloadEditor(); } } catch (FileFormatException e) { MessageBox.Show("Invalid file format loaded. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (IOException e) { MessageBox.Show("Unexpected error occurred while loading JSON file. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (SqlException e) { MessageBox.Show("Unexpected SQL error occurred while saving imported entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception) { MessageBox.Show("Unexpected error occurred while importing", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { AllowInput = true; } }
public bool CanMakeAccountTransaction(Account selectedAccount) { return(TransactionTypes.Any(x => x.CanMakeAccountTransaction(selectedAccount))); }