public Transaction executeTransaction(String cardNo, String pin, String accNo, Transaction tr)
        {
            if (authenticateTransaction(cardNo, pin))
            {
                logger("Thread : " + Thread.CurrentThread.Name +
                        " : Waiting till the lock in Account released to do the " +
                            tr.Type + " transaction for Ac : " + accNo);

                accountDAO.getAccountByAccNo(accNo)._isAvailableLockedData.WaitOne();

                logger("Thread : " + Thread.CurrentThread.Name
                    + " : Signal received to confirm that the lock has been released. Doing "
                                + tr.Type + " transaction for  Ac : " + accNo);

                tr = accountDAO.getAccountByAccNo(accNo).executeTransaction(tr);

                logger("Thread : " + Thread.CurrentThread.Name
                   + " : Completed  "
                               + tr.Type + " transaction for  Ac : " + accNo);
                if (!tr.Success) {
                    logger("Thread : " + Thread.CurrentThread.Name +
                        " : Error while excuting the transaction for Account : " + accNo);
                }
            }
            //throw new Exception("Failed to authenticate");

            return tr;
        }
Example #2
0
        private void transferMoney(double amount, String ac1, String ac2)
        {
            DebitCard card = main.currentCard;
                Transaction tr1 = new Transaction("debit", amount);
                Transaction tr2 = new Transaction("credit", amount);

                main.server.AccountService.executeTransaction(card.CardNumber, card.Pin, ac1, tr1);

                if (tr1.Success)
                {
                    main.server.AccountService.executeTransaction(card.CardNumber, card.Pin, ac2, tr2);
                    main.logWindow.logger("Money transfer from " + ac1 + " to " + ac2 + " sucessfull.");
                    MessageBox.Show("Money transfer from " + ac1 + " to " + ac2 + " sucessfull.");
                }
                else
                {
                    main.logWindow.logger("Money transfer from " + ac1 + " to " + ac2 + " unsucessfull.");
                    MessageBox.Show("Money transfer from " + ac1 + " to " + ac2 + " unsucessfull.\nMay be there's not sufficeint funds in " + ac1);
                }
        }
        public Transaction executeTransaction(Transaction t)
        {
            if (t.Type.Equals("debit")) {
                if (debitAccount(t.Amount))
                {
                    t.Balance = Balance;
                    t.Success = true;
                    addToTransactions(t);
                    return t;
                }
                else {
                    return t;
                }

            }
            else if (t.Type.Equals("credit"))
            {
                creditAccount(t.Amount);

                t.Balance = Balance;
                t.Success = true;
                addToTransactions(t);

                return t;
            }

            return t;
        }
 private void addToTransactions(Transaction t)
 {
     if (! (recentTransactions.Count < 25)){
         recentTransactions.RemoveAt(0);
     }
     recentTransactions.Add(t);
 }