Example #1
0
 public void TransferFunds(AccountTransferRequest accountTransfer) {
     var accountTransferCommand = new AccountTransferCommand {
         FromAccount = accountTransfer.FromAccount,
         ToAccount = accountTransfer.ToAccount,
         TransferAmount = accountTransfer.TransferAmount
     };
     _eventBus.SendCommand(accountTransferCommand);
 }
Example #2
0
        public async Task <IActionResult> Transfer([FromBody] AccountTransferRequest request)
        {
            var(succeeded, errorMessage) = await mediator.Send(request);

            if (succeeded)
            {
                return(Ok());
            }

            return(BadRequest(new BadRequestResponse(errorMessage)));
        }
        public IActionResult TransfetToAccount([FromBody] AccountTransferRequest accountTransferRequest)
        {
            var accountTransfer = new AccountTransfer
            {
                FromAccount    = accountTransferRequest.FromAccount,
                ToAccount      = accountTransferRequest.ToAccount,
                TransferAmount = accountTransferRequest.TransferAmount
            };

            _accountService.Transfer(accountTransfer);

            return(Ok(accountTransfer));
        }
Example #4
0
        public async Task <IActionResult> TransferAccount(AccountTransferRequest request)
        {
            var response = new BaseResponse <AccountTransferResponse>();
            var data     = new AccountTransferResponse();

            try
            {
                var accRepo     = new AccountRepository();
                var accountFrom = accRepo.GetAccountById(request.fromAccountId);
                var accountTo   = accRepo.GetAccountById(request.toAccountId);

                if (accountFrom == null)
                {
                    throw new AccountNotFoundException($"{request.fromAccountId}");
                }

                if (accountTo == null)
                {
                    throw new AccountNotFoundException($"{request.toAccountId}");
                }

                _service.TransferTo(accountFrom, accountTo, request.amount);

                accRepo.UpdateAccount(accountFrom);
                accRepo.UpdateAccount(accountTo);

                //consider using mapper such as automapper lib
                data.fromAccountAmount = accountFrom.Amount;
                data.toAccountAmount   = accountTo.Amount;

                response.SetData(data);
            }
            catch (Exception e)
            {
                response.SetError(e);
            }

            return(Ok(response));
        }
Example #5
0
 public IActionResult TransferFunds([FromBody] AccountTransferRequest request)
 {
     _accountService.TransferFunds(request);
     return(Ok());
 }