コード例 #1
0
        private void DepositMoney()
        {
            dError.Foreground = Brushes.PaleVioletRed;
            bool IsValidInput = true;

            int.TryParse(dAccountNumber.Text, out int accNumber);
            int.TryParse(dAmount.Text, out int amountToDeposit);

            //Validate Input
            if (dCustomerPIN.Password.Length < 4)
            {
                dError.Text = "Please enter a valid PIN";
            }
            else if ((dAccountNumber.Text.Length <= 0) || (accNumber <= 0))
            {
                dError.Text = "Please enter a valid Account Number";
            }
            else if ((dAmount.Text.Length <= 0) || (amountToDeposit <= 0))
            {
                dError.Text = "Please enter a valid Amount to Deposit";
            }
            else
            {
                using (var db = new MiniBankEntities())
                {
                    //Verify Customer And Account
                    currentActiveAccount =
                        db.Accounts.Where(a => a.CustomerID == LoggedInCustomer.CustomerID && a.AccountNumber == dAccountNumber.Text).FirstOrDefault();

                    if (db.Customers.Any(c => c.CustomerID == LoggedInCustomer.CustomerID && c.PIN == dCustomerPIN.Password))
                    {
                        if (currentActiveAccount != null)
                        {
                            //Deposit Money Into Account
                            int previousBalance = (int)currentActiveAccount.Amount;
                            currentActiveAccount.Amount += amountToDeposit;

                            Bank_Transaction transaction = new Bank_Transaction
                            {
                                Amount          = amountToDeposit,
                                TransactionType = 2,
                                AccountID       = currentActiveAccount.AccountID,
                                PreviousBalance = previousBalance,
                                NewBalance      = currentActiveAccount.Amount
                            };

                            db.Bank_Transaction.Add(transaction);

                            db.SaveChanges();

                            dCustomerPIN.Clear();
                            dAccountNumber.Clear();
                            dAmount.Clear();

                            if (LoggedInCustomer != null)
                            {
                                getCustomerAccounts(LoggedInCustomer);
                                CustomerAccountsList.ItemsSource = CustomerAccounts;
                                GetTransactionHistory();
                            }

                            dError.Text       = $"You have successfully deposited £{amountToDeposit} into Account: {accNumber}";
                            dError.Foreground = Brushes.LightGreen;
                        }
                        else
                        {
                            dError.Text = "Your account was not found, Please check your details and try again";
                        }
                    }
                    else
                    {
                        dError.Text = "The PIN you entered was incorrect, please try again.";
                    }
                }
            }
        }
コード例 #2
0
        private void WithdrawMoney()
        {
            //***********Add Foreign Transactions**********
            wError.Foreground = Brushes.PaleVioletRed;
            bool IsValidInput = true;

            int.TryParse(wAccountNumber.Text, out int accNumber);
            int.TryParse(wAmount.Text, out int amountToWithdraw);

            //Validate Input
            if (wCustomerPIN.Password.Length < 4)
            {
                wError.Text = "Please enter a valid PIN";
            }
            else if ((wAccountNumber.Text.Length <= 0) || (accNumber <= 0))
            {
                wError.Text = "Please enter a valid Account Number";
            }
            else if ((wAmount.Text.Length <= 0) || (amountToWithdraw <= 0))
            {
                wError.Text = "Please enter a valid Amount to Withdraw";
            }
            else
            {
                using (var db = new MiniBankEntities()) {
                    currentActiveAccount =
                        db.Accounts.Where(a => a.CustomerID == LoggedInCustomer.CustomerID && a.AccountNumber == wAccountNumber.Text).FirstOrDefault();

                    if (db.Customers.Any(c => c.CustomerID == LoggedInCustomer.CustomerID && c.PIN == wCustomerPIN.Password))
                    {
                        if (currentActiveAccount != null)
                        {
                            if (currentActiveAccount.Amount > amountToWithdraw)
                            {
                                int previousBalance = (int)currentActiveAccount.Amount;
                                currentActiveAccount.Amount -= amountToWithdraw;

                                Bank_Transaction transaction = new Bank_Transaction
                                {
                                    Amount          = amountToWithdraw,
                                    TransactionType = 1,
                                    AccountID       = currentActiveAccount.AccountID,
                                    PreviousBalance = previousBalance,
                                    NewBalance      = currentActiveAccount.Amount
                                };

                                db.Bank_Transaction.Add(transaction);

                                db.SaveChanges();

                                wCustomerPIN.Clear();
                                wAccountNumber.Clear();
                                wAmount.Clear();

                                if (LoggedInCustomer != null)
                                {
                                    getCustomerAccounts(LoggedInCustomer);
                                    CustomerAccountsList.ItemsSource = CustomerAccounts;
                                    GetTransactionHistory();
                                }

                                wError.Text       = $"You have successfully withdrawn £{amountToWithdraw} from Account: {accNumber}";
                                wError.Foreground = Brushes.LightGreen;
                            }
                            else
                            {
                                wError.Text = "You do not have enough funds in your account to complete this transaction";
                            }
                        }
                        else
                        {
                            wError.Text = "Your account was not found, Please check your details and try again";
                        }


                        //Verify Customer And Account
                    }
                    else
                    {
                        wError.Text = "The PIN you entered was incorrect, please try again.";
                    }
                    //Verify Availability Of Funds
                    //Withdraw Money From Account
                }
            }
        }