private async void BtnSubmit_Click(object sender, RoutedEventArgs e) { if (AppState.AllAccounts.All(account => account.Name != TxtAccountName.Text)) { Enum.TryParse(CmbAccountTypes.SelectedValue.ToString().Replace(" ", ""), out AccountTypes currentType); Account newAccount = new Account(TxtAccountName.Text, currentType, new List <Transaction>()); Transaction newTransaction = new Transaction(await AppState.GetNextTransactionsIndex(), DateTime.Now, "Income", "Income", "Starting Balance", "", 0.00M, DecimalHelper.Parse(TxtBalance.Text), newAccount.Name); newAccount.AddTransaction(newTransaction); if (await AppState.AddAccount(newAccount)) { if (await AppState.AddTransaction(newTransaction, newAccount)) { ClosePage(); } else { AppState.DisplayNotification("Unable to process new account.", "Finances"); } } } else { AppState.DisplayNotification("That account name already exists.", "Finances"); } }
/// <summary>Attempts to add a Transaction to the database.</summary> /// <returns>Returns true if successfully added</returns> private async Task <bool> AddTransaction() { Transaction newTransaction = new Transaction(await AppState.GetNextTransactionsIndex(), DateTimeHelper.Parse(TransactionDate.SelectedDate), TxtPayee.Text, CmbMajorCategory.SelectedValue.ToString(), CmbMinorCategory.SelectedValue.ToString(), TxtMemo.Text, DecimalHelper.Parse(TxtOutflow.Text), DecimalHelper.Parse(TxtInflow.Text), _selectedAccount.Name); _selectedAccount.AddTransaction(newTransaction); AppState.AllTransactions.Add(newTransaction); return(await AppState.AddTransaction(newTransaction, _selectedAccount)); }
/// <summary>Adds a transfer to the database.</summary> /// <returns>True if successful</returns> private async Task <bool> AddTransfer() { Transaction transferFrom = new Transaction(await AppState.GetNextTransactionsIndex(), DateTimeHelper.Parse(TransferDate.SelectedDate), "Transfer", "Transfer", "Transfer", _transferToAccount.Name, DecimalHelper.Parse(TxtTransferAmount.Text), 0.00M, _transferFromAccount.Name); _transferFromAccount.AddTransaction(transferFrom); Transaction transferTo = new Transaction(await AppState.GetNextTransactionsIndex() + 1, DateTimeHelper.Parse(TransferDate.SelectedDate), "Transfer", "Transfer", "Transfer", _transferFromAccount.Name, 0.00M, DecimalHelper.Parse(TxtTransferAmount.Text), _transferToAccount.Name); _transferToAccount.AddTransaction(transferTo); if (await AppState.AddTransaction(transferFrom, _transferFromAccount)) { if (await AppState.AddTransaction(transferTo, _transferToAccount)) { return(true); } } return(false); }