Esempio n. 1
0
        public void Test_AllTransactionsSuccessful()
        {
            var transactionManager = new TransactionManager();

            var suesAccount = new Account("Sue Smith", 0);

            var deposit = new Deposit(suesAccount, 100);

            transactionManager.AddTransaction(deposit);

            // Command has been added to the queue, but not executed.
            Assert.True(transactionManager.HasPendingTransactions);
            Assert.Equal(0, suesAccount.Balance);

            // This executes the commands.
            transactionManager.ProcessPendingTransactions();

            Assert.False(transactionManager.HasPendingTransactions);
            Assert.Equal(100, suesAccount.Balance);

            // Add a withdrawal, apply it, and verify the balance changed.
            var withdrawal = new Withdraw(suesAccount, 50);

            transactionManager.AddTransaction(withdrawal);

            transactionManager.ProcessPendingTransactions();

            Assert.False(transactionManager.HasPendingTransactions);
            Assert.Equal(50, suesAccount.Balance);
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            // Invoker
            TransactionManager transactionManager = new TransactionManager();

            // Receiver
            Account myAccount  = new Account("Rajiv Ranjan", 100000);
            Account hisAccount = new Account("Ribha Singh", 25000);

            PrintStatement(myAccount, hisAccount);
            // Command
            Deposit  deposit  = new Deposit(myAccount, 100);
            Transfer transfer = new Transfer(myAccount, hisAccount, 25000);

            // Add commans to transaction manager (invoker)
            transactionManager.AddTransaction(deposit);
            transactionManager.AddTransaction(transfer);

            // Execute commands
            transactionManager.ProcessPendingTransactions();

            Console.WriteLine("\n************** After Transaction *********************");
            PrintStatement(myAccount, hisAccount);

            Console.Read();
        }
Esempio n. 3
0
        public void Test_AllTransactionsSuccessful()
        {
            TransactionManager transactionManager = new TransactionManager();

            Account suesAccount = new Account("Sue Smith", 0);

            Deposit deposit = new Deposit(suesAccount, 100);

            transactionManager.AddTransaction(deposit);

            // Command is added to the queue, but not executed
            Assert.IsTrue(transactionManager.HasPendingTransactions);
            Assert.AreEqual(0, suesAccount.Balance);

            //This executes the commands
            transactionManager.ProcessPendingTransactions();

            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(100, suesAccount.Balance);

            // Add a withdrawal, apply, and verify the balance changed
            Withdraw withdrawal = new Withdraw(suesAccount, 50);

            transactionManager.AddTransaction(withdrawal);

            transactionManager.ProcessPendingTransactions();

            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(50, suesAccount.Balance);
        }
Esempio n. 4
0
        public void Test_OverdraftRemainsInPendingTransactions()
        {
            TransactionManager transactionManager = new TransactionManager();

            //Create an account with a balance of 75
            Account bobsAccount = new Account("Bob Jones", 75);

            // The first command is a withdrawal that is larger than the account's balance
            // Command will not execute, because of the check in Withdraw.Execute
            // The deposit will be successful
            transactionManager.AddTransaction(new Withdraw(bobsAccount, 100));
            transactionManager.AddTransaction(new Deposit(bobsAccount, 75));

            transactionManager.ProcessPendingTransactions();

            // The Withdrawal of 100 is not complete because there was not enough money in the account.
            // Therefore, it is still pending
            Assert.IsTrue(transactionManager.HasPendingTransactions);
            Assert.AreEqual(150, bobsAccount.Balance);

            // The pending transactions (the withdrawal of 100), should execute now
            transactionManager.ProcessPendingTransactions();

            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(50, bobsAccount.Balance);
        }
Esempio n. 5
0
        public void Test_AllTransactionsSuccessful()
        {
            TransactionManager transactionManager = new TransactionManager();

            Account anniesAccount = new Account("Annie", 0);

            Deposit deposit = new Deposit(1, anniesAccount, 100);

            transactionManager.AddTransaction(deposit);

            // Command has been added to the queue, but not yet executed
            Assert.IsTrue(transactionManager.HasPendingTransactions);
            Assert.AreEqual(anniesAccount.Balance, 0);

            // This executes the commands
            transactionManager.ProcessPendingTransactions();
            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(anniesAccount.Balance, 100);

            // Add a withdrawal, apply it and check the balance changed
            Withdraw withdraw = new Withdraw(2, anniesAccount, 50);

            transactionManager.AddTransaction(withdraw);
            transactionManager.ProcessPendingTransactions();
            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(anniesAccount.Balance, 50);

            // Test the Undo
            transactionManager.UndoTransactionNumber(2);
            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(anniesAccount.Balance, 100);
        }
Esempio n. 6
0
        public static void Test_OverdraftRemainsInPendingTransactions()
        {
            var transactionManager = new TransactionManager();

            // Create an account with a balance of 75
            var bobsAccount = new Account("Bob Jones", 75);

            // The first command is a withdrawal that is larger than the account's balance.
            // It will not be executed, because of the check in Withdraw.Execute.
            // The deposit will be successful.
            transactionManager.AddTransaction(new Withdraw(1, bobsAccount, 100));
            transactionManager.AddTransaction(new Deposit(2, bobsAccount, 75));

            transactionManager.ProcessPendingTransactions();

            // The withdrawal of 100 was not completed,
            // because there was not enough money in the account.
            // So, it is still pending.
            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Bob's account balance: {0}", bobsAccount.Balance);

            // The pending transactions (the withdrawal of 100), should execute now.
            transactionManager.ProcessPendingTransactions();

            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Bob's account balance: {0}", bobsAccount.Balance);

            // Test the undo
            transactionManager.UndoTransactionNumber(2);

            // The undo failed, because there is not enough money in the account to undo a deposit of 75
            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Bob's account balance: {0}", bobsAccount.Balance);

            transactionManager.UndoTransactionNumber(1);

            // The previous undo (for transaction ID 2) is still pending.
            // But, we successfully undid transaction ID 1.
            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Bob's account balance: {0}", bobsAccount.Balance);

            // This should re-do the failed undo for transaction ID 2
            transactionManager.ProcessPendingTransactions();

            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Bob's account balance: {0}", bobsAccount.Balance);
        }
Esempio n. 7
0
        public void AddTransactionParametrsTest()
        {
            var clientManagerMock           = Substitute.For <IClientManager>();
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var clientRepositoryMock        = Substitute.For <IClientRepository>();
            var sharesRepositoryMock        = Substitute.For <ISharesRepository>();
            var transactionRepositoryMock   = Substitute.For <ITransactionRepository>();

            var sut = new TransactionManager(
                clientManagerMock,
                blockOfSharesRepositoryMock,
                clientRepositoryMock,
                sharesRepositoryMock,
                transactionRepositoryMock);

            int sellerID    = 3;
            int buyerID     = 5;
            int shareID     = 9;
            int shareAmount = 1;

            // Act
            sut.AddTransaction(sellerID, buyerID, shareID, shareAmount);

            // Asserts
            transactionRepositoryMock.Received(1).Insert(Arg.Is <Transaction>(t => t.BuyerID == buyerID &&
                                                                              t.SellerID == sellerID &&
                                                                              t.ShareID == shareID &&
                                                                              t.Amount == shareAmount));
        }
        public int AddBalanceByTransaction(Transaction transaction)
        {
            TransactionManager transactionManager = new TransactionManager();

            User userToAddBalance = GetUserByUserId(transaction.OperatedToUserId);

            double?newBalance = userToAddBalance.AccountBalance + transaction.Amount;

            string sql = "UPDATE [User] " +
                         "SET AccountBalance = @accountBalance  " +
                         "Where Id = @id";

            Command = new SqlCommand(sql, Connection);

            Command.Parameters.AddWithValue("@accountBalance", newBalance);
            Command.Parameters.AddWithValue("@id", userToAddBalance.Id);


            Connection.Open();

            int rowEffected = Command.ExecuteNonQuery();

            Connection.Close();

            if (rowEffected >= 0)
            {
                transactionManager.AddTransaction(transaction);
            }


            return(rowEffected);
        }
Esempio n. 9
0
        public void AddTransactionTest()
        {
            var clientManagerMock           = Substitute.For <IClientManager>();
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var clientRepositoryMock        = Substitute.For <IClientRepository>();
            var sharesRepositoryMock        = Substitute.For <ISharesRepository>();
            var transactionRepositoryMock   = Substitute.For <ITransactionRepository>();

            var sut = new TransactionManager(
                clientManagerMock,
                blockOfSharesRepositoryMock,
                clientRepositoryMock,
                sharesRepositoryMock,
                transactionRepositoryMock);
            var transaction = new Transaction
            {
                SellerID = 3,
                BuyerID  = 5,
                ShareID  = 9,
                Amount   = 1
            };

            // Act
            sut.AddTransaction(transaction);

            // Asserts
            transactionRepositoryMock.Received(1).Insert(Arg.Is <Transaction>(transaction));
        }
Esempio n. 10
0
        public void Test_OverdraftRemainsInPendingtransactions()
        {
            TransactionManager transactionManager = new TransactionManager();

            // Create an account with a balance of 75
            Account bobsAccount = new Account("Bob", 75);

            // The first command is a withdrawal larger than the account's balance
            // It will not be executed, because of the check in Withdraw.Execute
            // The deposit will be successful
            transactionManager.AddTransaction(new Withdraw(1, bobsAccount, 100));
            transactionManager.AddTransaction(new Deposit(2, bobsAccount, 75));
            transactionManager.ProcessPendingTransactions();

            // The withdrawal of 100 was not completed
            // because there was not eough money in the account
            // So, it is still pending
            Assert.IsTrue(transactionManager.HasPendingTransactions);
            Assert.AreEqual(bobsAccount.Balance, 150);

            // The pending transactions (the withdrawal of 100) should execute now
            transactionManager.ProcessPendingTransactions();
            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(bobsAccount.Balance, 50);

            // Test the Undo
            transactionManager.UndoTransactionNumber(2);

            // The Undo failed, because there is not enough money on the account to undo
            Assert.IsTrue(transactionManager.HasPendingTransactions);
            Assert.AreEqual(bobsAccount.Balance, 50);

            transactionManager.UndoTransactionNumber(1);

            // The previous Undo (for transaction ID 2) is still pending
            // But we successfully undid transaction ID 1
            Assert.IsTrue(transactionManager.HasPendingTransactions);
            Assert.AreEqual(bobsAccount.Balance, 150);

            // This should re-do the failed Undo for transaction ID 2
            transactionManager.ProcessPendingTransactions();
            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(bobsAccount.Balance, 75);
        }
Esempio n. 11
0
        public static void Test_AllTransactionsSuccessful()
        {
            var transactionManager = new TransactionManager();

            var suesAccount = new Account("Sue Smith", 0);

            var deposit = new Deposit(1, suesAccount, 100);

            transactionManager.AddTransaction(deposit);

            // Command has been added to the queue, but not executed.
            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Sue's account balance: {0}", suesAccount.Balance);

            // This executes the commands.
            transactionManager.ProcessPendingTransactions();

            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Sue's account balance: {0}", suesAccount.Balance);

            // Add a withdrawal, apply it, and verify the balance changed.
            var withdrawal = new Withdraw(2, suesAccount, 50);

            transactionManager.AddTransaction(withdrawal);

            transactionManager.ProcessPendingTransactions();

            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Sue's account balance: {0}", suesAccount.Balance);

            // Test the undo
            transactionManager.UndoTransactionNumber(2);

            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Sue's account balance: {0}", suesAccount.Balance);
        }
        public void Test_Transfer()
        {
            TransactionManager transactionManager = new TransactionManager();

            Account checking = new Account("Mike Brown", 1000);
            Account savings  = new Account("Mike Brown", 100);

            transactionManager.AddTransaction(new Transfer(checking, savings, 750));
            transactionManager.ProcessPendingTransactions();

            Assert.AreEqual(250, checking.Balance);
            Assert.AreEqual(850, savings.Balance);
        }
        public void LogTransaction(string customerId, string title, decimal newAvailableAmount, TransactionDTO transactionDTO)
        {
            var transaction = new Transaction();

            transaction.CustomerId      = customerId;
            transaction.DebitProductId  = transactionDTO.DebitProductId;
            transaction.CreditProductId = transactionDTO.CreditProductId;
            transaction.Amount          = transactionDTO.Amount;
            transaction.TransactionType = "debit";
            transaction.Beneficiary     = transactionDTO.Beneficiary;
            transaction.Bank            = transactionDTO.Bank;
            transaction.Currency        = transactionDTO.Currency;
            transaction.Title           = title;
            transaction.NewBalance      = newAvailableAmount;
            transaction.Date            = transactionDTO.IsAsap ? DateTime.Now : transactionDTO.Date;
            transactionManager.AddTransaction(transaction);
        }
Esempio n. 14
0
        public void DepositAccountCheckBalanceAndThenWithdraw_AllTransactionsSuccessful()
        {
            // Create Account with Balance 0
            var initialAccount1 = new Account()
            {
                Balance = 0, AccountGuid = Guid.NewGuid()
            };

            // Add a deposit reqest of 100 to that account
            _transactionManager.AddTransaction(new Deposit(initialAccount1, 100));

            // Pre-check : transactionManager Should have pending transactions at this point
            Assert.IsTrue(_transactionManager.HasPendingTransactions());

            // Account Balance Should be 0 at this point
            Assert.AreEqual(initialAccount1.Balance, 0);

            // Run ProcessPendingTransactions() to process Pending TransactionRequests
            _transactionManager.ProcessPendingTransactions();

            // Check : there should not be any pending Transactions now
            Assert.IsFalse(_transactionManager.HasPendingTransactions());

            // Check balance of the account which should be 100 now
            Assert.AreEqual(initialAccount1.Balance, 100);

            // Create a Withdraw of 50 on that account
            _transactionManager.AddTransaction(new Withdraw(initialAccount1, 50));

            // Perform a ProcessPendingTransactions() to process this
            _transactionManager.ProcessPendingTransactions();

            // check : No pending Transactions at this point
            Assert.IsFalse(_transactionManager.HasPendingTransactions());

            // Check balance: should be 100-50 =50
            Assert.AreEqual(initialAccount1.Balance, 50);
        }
Esempio n. 15
0
        protected void AddNewTransaction(TransactionStrings data, int entry)
        {
            try
            {
                Date    date      = new Date(data.GetDate());
                Account sender    = accounts.GetAccount(data.GetSender());
                Account recipient = accounts.GetAccount(data.GetRecipient());
                Money   amount    = new Money(data.GetAmount());

                Transaction transaction = new Transaction(date, sender, recipient, data.GetNarrative(), amount);
                transactions.AddTransaction(transaction);
            }
            catch (ArgumentException ae)
            {
                WriteErrorToConsoleFirstTime();
                LogBadFormatTransaction(entry, ae.Message);
            }
        }
Esempio n. 16
0
        public void Test_Transfert()
        {
            TransactionManager transactionManager = new TransactionManager();

            Account checking = new Account("Charlie", 1000);
            Account savings  = new Account("Dimitri", 100);

            transactionManager.AddTransaction(new Transfert(1, checking, savings, 750));
            transactionManager.ProcessPendingTransactions();

            Assert.AreEqual(checking.Balance, 250);
            Assert.AreEqual(savings.Balance, 850);

            // Test the Undo
            transactionManager.UndoTransactionNumber(1);
            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(checking.Balance, 1000);
            Assert.AreEqual(savings.Balance, 100);
        }
Esempio n. 17
0
        public void Test_Transfer()
        {
            TransactionManager transactionManager = new TransactionManager();

            Account checking = new Account("Mike Brown", 1000);
            Account savings  = new Account("Mike Brown", 100);

            transactionManager.AddTransaction(new Transfer(1, checking, savings, 750));

            transactionManager.ProcessPendingTransactions();

            Assert.AreEqual(250, checking.Balance);
            Assert.AreEqual(850, savings.Balance);

            // Undo the transfer, and check the account balances.
            transactionManager.UndoTransactionNumber(1);

            Assert.IsFalse(transactionManager.HasPendingTransactions);
            Assert.AreEqual(1000, checking.Balance);
            Assert.AreEqual(100, savings.Balance);
        }
Esempio n. 18
0
        public void DepositAccountCheckBalanceAndThenWithdraw_AllTransactionsSuccessful()
        {
            Account sumonAccount = new Account("Sumon", 0);
            Deposit deposit      = new Deposit(sumonAccount, 100);

            _transactionManager.AddTransaction(deposit);

            Assert.IsTrue(_transactionManager.HasPendingTransactions);
            Assert.AreEqual(0, sumonAccount.Balance);

            _transactionManager.ProcessPendingTransactions();

            Assert.IsFalse(_transactionManager.HasPendingTransactions);
            Assert.AreEqual(100, sumonAccount.Balance);
            Withdraw withdrawal = new Withdraw(sumonAccount, 50);

            _transactionManager.AddTransaction(withdrawal);

            _transactionManager.ProcessPendingTransactions();

            Assert.IsFalse(_transactionManager.HasPendingTransactions);
            Assert.AreEqual(50, sumonAccount.Balance);
        }
Esempio n. 19
0
        public object CreateNewTransaction(string transactionName)
        {
            var provider = (ICustomErrorPagesEFDataProvider)this.DataProvider;

            if (string.IsNullOrEmpty(transactionName))
            {
                return(this.GetContext(provider));
            }

            string id    = GetScopeId(provider);
            var    scope = TransactionManager.GetTransaction <object>(transactionName, id);

            if (scope == null)
            {
                var context = this.GetContext(provider);
                context.BeginTransaction();
                TransactionManager.AddTransaction(transactionName, id, this, context);
                scope = context;
            }

            return(scope);
        }
Esempio n. 20
0
        public static void Test_Transfer()
        {
            var random = new Random();

            var transactionManager = new TransactionManager();

            var checking = new Account("Mike Brown", 1000);
            var savings  = new Account("Mike Brown", 100);

            transactionManager.AddTransaction(new Transfer(random.Next(), checking, savings, 750));

            transactionManager.ProcessPendingTransactions();

            Console.WriteLine("Mike Brown's checking account balance: {0}", checking.Balance);
            Console.WriteLine("Bob's savings account balance: {0}", savings.Balance);

            // Undo the transfer, and check the account balances.
            transactionManager.UndoTransactionNumber(1);

            Console.WriteLine("Transaction Manager has pending transactions? {0}",
                              transactionManager.HasPendingTransactions);
            Console.WriteLine("Mike Brown's checking account balance: {0}", checking.Balance);
            Console.WriteLine("Bob's savings account balance: {0}", savings.Balance);
        }
Esempio n. 21
0
        private static void CreateTransaction()
        {
            if (AccountList.Count != 0)
            {
                var     transactionManager = new TransactionManager();
                Account account            = null;

                while (account == null)
                {
                    Console.WriteLine(Translator.GetTranslation("ChooseAccount"));
                    var accountName = Console.ReadLine();

                    if (AccountList.Any(x => x.Name.ToLower() == accountName.ToLower()))
                    {
                        account = AccountList.SingleOrDefault(x => x.Name.ToLower() == accountName.ToLower());
                    }
                }

                // Get transaction type
                while (true)
                {
                    Console.WriteLine(Translator.GetTranslation("TransactionType"));
                    var type = Console.ReadLine();
                    if (type.ToLower().Equals("transfer"))
                    {
                        Account accountToTransferTo = null;
                        while (accountToTransferTo == null)
                        {
                            Console.WriteLine(Translator.GetTranslation("ChooseAccount"));
                            var accountName = Console.ReadLine();
                            if (AccountList.Any(x => x.Name.ToLower() == accountName.ToLower()))
                            {
                                accountToTransferTo = AccountList.SingleOrDefault(x => x.Name.ToLower() == accountName.ToLower());
                            }
                        }
                        Console.WriteLine(Translator.GetTranslation("AmountToTransfer"));
                        var amount   = Convert.ToDouble(Console.ReadLine());
                        var transfer = new Transfer(account, accountToTransferTo, amount);
                        transactionManager.AddTransaction(transfer);

                        Console.WriteLine(Translator.GetTranslation("TransactionPrice") + account.TransactionStrategy.GetTransactionFee() + '$');

                        Console.WriteLine(Translator.GetTranslation("TransactionComplete"));
                        var complete = (Console.ReadKey().KeyChar == 'y') ? true : false;
                        Console.WriteLine();

                        if (complete)
                        {
                            transactionManager.ProcessTransactions();
                        }

                        SeeAccounts();
                        break;
                    }
                    else if (type.ToLower().Equals("deposit"))
                    {
                        Console.WriteLine(Translator.GetTranslation("AmountToDeposit"));
                        var amount = Convert.ToDouble(Console.ReadLine());

                        var deposit = new Deposit(account, amount);
                        transactionManager.AddTransaction(deposit);

                        Console.WriteLine(Translator.GetTranslation("TransactionPrice") + account.TransactionStrategy.GetTransactionFee() + '$');

                        Console.WriteLine(Translator.GetTranslation("TransactionComplete"));
                        var complete = (Console.ReadKey().KeyChar == 'y') ? true : false;
                        Console.WriteLine();

                        if (complete)
                        {
                            transactionManager.ProcessTransactions();
                        }

                        SeeAccounts();
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine(Translator.GetTranslation("AccountMissing"));
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Programme très simple qui n'a qu'un seul but : Implémenter le command Design pattern.
        /// Main est ici le Client qui va faire appel à l'invoker (transactionmanager) pour exécuter des Command
        /// qui vont agir sur le business Object (account)
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            try
            {
                bool continuer = true;
                TransactionManager transactionManager = new TransactionManager();

                Account compteGeoffrey = new Account("Geoffrey", 20000);
                Account compteLorena   = new Account("Lorena", 5000);

                // Ajout d'une commande :
                ITransaction commande;
                Console.WriteLine("Geoffrey a " + compteGeoffrey.Balance + "et Lorena a " + compteLorena.Balance);

                while (continuer)
                {
                    Console.WriteLine("Choisir une commande : W/D/T");
                    var cle = Console.ReadKey();
                    switch (cle.KeyChar)
                    {
                    case 'w':
                        Console.WriteLine("Ajout commande Withdraw sur compte Geoffrey de 500");
                        commande = new WithdrawCommand(compteGeoffrey, 500);
                        break;

                    case 'd':
                        Console.WriteLine("Deposit sur compte Lorena de 300");
                        commande = new DepositCommand(compteLorena, 300);
                        break;

                    case 't':
                        Console.WriteLine("Transfert de Lorena vers Geoffrey de 400");
                        commande = new TransferCommand(compteLorena, compteGeoffrey, 400);
                        break;

                    default:
                        throw new Exception();
                    }
                    transactionManager.AddTransaction(commande);

                    Console.WriteLine("Geoffrey a " + compteGeoffrey.Balance + "et Lorena a " + compteLorena.Balance);

                    Console.WriteLine("Executer les commandes ? (y/n)");
                    var executer = Console.ReadKey();
                    if (executer.KeyChar == 'y')
                    {
                        transactionManager.ProcessPendingTransactions();
                    }
                    Console.WriteLine("Geoffrey a " + compteGeoffrey.Balance + "et Lorena a " + compteLorena.Balance);

                    Console.WriteLine("Quitter ?(y/n)");
                    var quitter = Console.ReadKey();
                    if (quitter.KeyChar == 'y')
                    {
                        continuer = false;
                    }
                }
            }
            catch
            {
                Console.WriteLine("Mauvais input, programme fait à l'arrache dans le seul but d'implémenter le Command Design pattern, respecter la casse.");
                Console.ReadKey();
            }
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            //check if fields are blank
            if (txtTransactionName.Text == "")
            {
                MessageBox.Show("You need to enter a Transaction Name");
                txtTransactionName.Focus();
                return;
            }
            if (cmbTransactionType.SelectedItem == null)
            {
                MessageBox.Show("You need to Select a Type");
                cmbTransactionType.Focus();
                return;
            }
            if (numAmount.Value == 0.00m)
            {
                MessageBox.Show("Amount Value needs to be above 0.00");
                numAmount.Focus();
                return;
            }

            //create objects
            var transaction = new Transaction();

            transaction.Name = txtTransactionName.Text;
            transaction.Date = dtpDate.Value.ToString("yyyy-MM-dd");
            transaction.Type = cmbTransactionType.SelectedItem.ToString();

            // create object for amount value depentent on transaction type
            if (cmbTransactionType.SelectedIndex == 0)             //Income
            {
                transaction.Amount = numAmount.Value.ToString();
            }
            else             //Expense
            {
                decimal newAmount = numAmount.Value * -1;
                transaction.Amount = newAmount.ToString();
            }


            //save record
            if (editMode == true)
            {
                _transactionManager.EditTransaction(transaction, _transactionIndex);
                this.Close();
            }
            else
            {
                int transactionCount = _transactionManager.TransactionList.Count;
                var newList          = _transactionManager.AddTransaction(transaction);
                if (newList.Count > transactionCount)
                {
                    MessageBox.Show("New Transaction Added.");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Add Failed.");
                    this.Close();
                }
            }
        }