public IActionResult Withdraw(TransactionWithdrawViewModel viewModel)
        {
            var account    = _repository.GetAccountById(viewModel.AccountId);
            var sufficient = _repository.CheckIfSufficientBalance(viewModel.AmountToWithdraw, account.Balance);

            if (!sufficient)
            {
                ModelState.AddModelError("AmountToWithdraw", "Amount can not be greater than balance");
            }

            if (ModelState.IsValid)
            {
                var trans = new Transaction();

                trans.Balance           = account.Balance - viewModel.AmountToWithdraw;
                trans.AccountId         = account.AccountId;
                trans.Date              = DateTime.Now.Date;
                trans.Operation         = "Withdrawal in Cash";
                trans.Type              = "Credit";
                trans.Symbol            = "";
                trans.Amount            = -viewModel.AmountToWithdraw;
                trans.AccountNavigation = account;

                account.Balance -= viewModel.AmountToWithdraw;
                account.Transactions.Add(trans);

                _repository.UpdateAccount(account);
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
        public IActionResult Withdraw(TransactionWithdrawViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            _service.Withdraw(model);

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

            return(View(viewModel));
        }
示例#4
0
        public void Withdraw_Amount_Higher_Then_Balance_Should_Return_One_ErrorMessage()
        {
            TransactionWithdrawViewModel model = new TransactionWithdrawViewModel
            {
                AccountId      = 1,
                CustomerId     = 1,
                Balance        = 20000m,
                WithdrawAmount = 20001m
            };

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

            Assert.AreEqual(1, errorcount);
        }
示例#5
0
        public void Withdraw(TransactionWithdrawViewModel model)
        {
            _transactionRepository.PostTransaction(new Transactions
            {
                AccountId = model.AccountId,
                Amount    = -model.WithdrawAmount,
                Balance   = model.Balance - model.WithdrawAmount,
                Date      = DateTime.Now,
                Type      = "Debit",
                Operation = "Withdraw in Cash"
            });

            var account = _accountRepository.GetAccount(model.AccountId);

            account.Balance = account.Balance - model.WithdrawAmount;

            _accountRepository.UpdateAccount(account);
        }
        public IActionResult Withdraw()
        {
            var viewModel = new TransactionWithdrawViewModel();

            return(View(viewModel));
        }