public void TransferMoney(TransactionTransferToAccountViewModel model)
        {
            _transactionRepository.PostTransaction(new Transactions
            {
                AccountId = model.AccountId,
                Amount    = -model.TransferAmount,
                Balance   = model.Balance - model.TransferAmount,
                Date      = DateTime.Now,
                Type      = "Debit",
                Operation = "Remittance to Account",
                Account   = model.AccountIdSendTo.ToString()
            });
            var account = _accountRepository.GetAccount(model.AccountId);

            account.Balance = account.Balance - model.TransferAmount;
            _accountRepository.UpdateAccount(account);

            var toAccount = _accountRepository.GetAccount(model.AccountIdSendTo);

            toAccount.Balance = toAccount.Balance + model.TransferAmount;
            _accountRepository.UpdateAccount(toAccount);

            _transactionRepository.PostTransaction(new Transactions
            {
                AccountId = model.AccountIdSendTo,
                Amount    = model.TransferAmount,
                Balance   = toAccount.Balance,
                Date      = DateTime.Now,
                Type      = "Credit",
                Operation = "Collection from Another Account",
                Account   = model.AccountId.ToString()
            });
        }
        public IActionResult Transfer(TransactionTransferToAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            _service.TransferMoney(model);

            return(RedirectToAction("ViewCustomer", "Customer", new { id = model.CustomerId }));
        }
        public IActionResult Transfer(int accountId, int customerId)
        {
            var viewModel = new TransactionTransferToAccountViewModel
            {
                AccountId  = accountId,
                Balance    = _service.GetBalance(accountId),
                CustomerId = customerId
            };

            return(View(viewModel));
        }
Beispiel #4
0
        public void AccountIdSendTo_Not_Exist_In_Database_Should_Return_One_ErrorMessage()
        {
            TransactionTransferToAccountViewModel model = new TransactionTransferToAccountViewModel
            {
                AccountId       = 1,
                CustomerId      = 1,
                Balance         = 20000m,
                TransferAmount  = 15000m,
                AccountIdSendTo = 0
            };

            var errorcount = model.Validate(validationContext).Count();

            Assert.AreEqual(1, errorcount);
        }
Beispiel #5
0
        public void Transfer_Amount_Higher_Then_Balance_Should_Return_One_ErrorMessage()
        {
            TransactionTransferToAccountViewModel model = new TransactionTransferToAccountViewModel
            {
                AccountId       = 1,
                CustomerId      = 1,
                Balance         = 20000m,
                TransferAmount  = 210000m,
                AccountIdSendTo = 2
            };

            var errorcount = model.Validate(validationContext).Count();

            Assert.AreEqual(1, errorcount);
        }