Example #1
0
        public IActionResult Withdraw(Models.ActivityRequest request)
        {
            // Make sure amount is greater than zero
            if (request.Amount > 0)
            {
                // Update Balance
                Models.Balance accountBalance = _balanceRepository.GetBalanceById(request.AccountId);

                // Make sure balance can cover withdrawal
                if (accountBalance.CurrentBalance >= request.Amount)
                {
                    accountBalance.CurrentBalance -= request.Amount;
                    Models.Balance result = _balanceRepository.UpdateBalance(accountBalance);

                    // Add Activity
                    _activityRepository.CreateActivity(new Models.Activity {
                        AccountId = request.AccountId, Amount = request.Amount, ActivityTypeId = Models.ActivityType.Withdrawal
                    });
                    return(Accepted(result));
                }
                else
                {
                    return(BadRequest("Not enough funds available to withdraw."));
                }
            }
            else
            {
                return(BadRequest("Amount must be greater than zero."));
            }
        }
Example #2
0
        public IActionResult Deposit(Models.ActivityRequest request)
        {
            // Make sure amount is greater than zero
            if (request.Amount > 0)
            {
                // Update Balance
                Models.Balance accountBalance = _balanceRepository.GetBalanceById(request.AccountId);
                accountBalance.CurrentBalance += request.Amount;
                Models.Balance result = _balanceRepository.UpdateBalance(accountBalance);

                // Add Activity
                _activityRepository.CreateActivity(new Models.Activity {
                    AccountId = request.AccountId, Amount = request.Amount, ActivityTypeId = Models.ActivityType.Deposit
                });

                return(Accepted(result));
            }
            else
            {
                return(BadRequest("Amount must be greater than zero."));
            }
        }