Exemplo n.º 1
0
        private void createAccount(object o)
        {
            if (Validator.ValidAccountCreationName(accountName) && Validator.ValidDouble(accountBalance))
            {
                string name      = accountName.ToUpper().Trim();
                string accountId = RandomGenerator.GenerateAccountId(name);

                account = new AccountModel(accountId, name, accountBalance);
                AccountModel.AccountDictionary.Add(accountId, account);
                obcAccounts.Add(account);

                SelectedAccount = account;
                AccountName     = null;
                AccountBalance  = null;
            }
            else
            {
                accountSnackbarMessage(4500, "Please enter a valid account name and balance.");
            }
            int accountCount = obcAccounts.Count;

            CanTransfer     = Validator.CanTransferBtnEnabledCheck(accountCount);
            CanActOnAccount = Validator.AccountIsSelectedCheck(accountCount, SelectedAccount);
            refreshAll();
        }
Exemplo n.º 2
0
 private void deleteTransaction(object o)
 {
     // ReSharper disable once AssignmentInConditionalExpression
     if (CanActOnTransaction =
             Validator.TransactionIsSelectedAndHasIdCheck(obcTransactions.Count, SelectedTransaction) &&
             Validator.AccountIsSelectedCheck(obcAccounts.Count, SelectedAccount))
     {
         account = AccountModel.AccountDictionary[selectedAccount.Id];
         AccountModel.UpdateBalance(account, -selectedTransaction.Amount, selectedTransaction.Type);
         account.DeleteTransaction(selectedTransaction.Id);
         refreshAll();
     }
     else
     {
         accountSnackbarMessage(4500, "Please choose a transaction to remove");
     }
 }
Exemplo n.º 3
0
        public AccountViewModel()
        {
            string username = Environment.GetEnvironmentVariable("UserName");

            if (DataProvider.LoadAccountDictionary())
            {
                accountSnackbarMessage(4500, "Welcome back, " + username);
                SelectedAccount = AccountModel.AccountDictionary.ElementAt(0).Value;
            }
            else
            {
                accountSnackbarMessage(5000, "Hi, " + username + ". Data will be automatically saved when the app is closed.");
            }

            obcAccounts = new ObservableCollection <AccountModel>(AccountModel.AccountDictionary.Values);

            if (SelectedAccount != null)
            {
                if (SelectedAccount.TransactionDictionary != null)
                {
                    obcTransactions =
                        new ObservableCollection <TransactionModel>(SelectedAccount.TransactionDictionary.Values);
                }
                CanActOnTransaction =
                    Validator.TransactionIsSelectedAndHasIdCheck(obcTransactions.Count, SelectedTransaction);
            }

            createTransactionTypeFilterList();
            selectedDate = DateTime.Today;

            int accountCount = obcAccounts.Count;

            CanActOnAccount = Validator.AccountIsSelectedCheck(accountCount, SelectedAccount);
            CanTransfer     = Validator.CanTransferBtnEnabledCheck(accountCount);

            CmdCreateAccount      = new RelayCommand(createAccount, param => true);
            CmdCreateTestAccounts = new RelayCommand(createTestAccounts, param => true);
            CmdSaveTransfer       = new RelayCommand(transferBetweenAccounts, param => true);
            CmdDeleteAccount      = new RelayCommand(deleteAccount, param => true);
            CmdDeleteTransaction  = new RelayCommand(deleteTransaction, param => true);
            CmdUpdateBalance      = new RelayCommand(updateBalance, param => true);
        }
Exemplo n.º 4
0
 private void deleteAccount(object o)
 {
     if (!(CanActOnAccount = Validator.AccountIsSelectedCheck(obcAccounts.Count, SelectedAccount)))
     {
         return;
     }
     AccountModel.AccountDictionary.Remove(SelectedAccount.Id);
     ObcAccounts = new ObservableCollection <AccountModel>(AccountModel.AccountDictionary.Values);
     CanTransfer = Validator.CanTransferBtnEnabledCheck(obcAccounts.Count);
     if (ObcAccounts.Count >= 1)
     {
         SelectedAccount     = ObcAccounts[0];
         CanActOnAccount     = Validator.AccountIsSelectedCheck(obcAccounts.Count, SelectedAccount);
         CanActOnTransaction =
             Validator.TransactionIsSelectedAndHasIdCheck(obcTransactions.Count, SelectedTransaction);
     }
     else
     {
         ObcTransactions     = null;
         CanActOnAccount     = false;
         CanActOnTransaction = false;
     }
 }