コード例 #1
0
        public async Task <AccountWithdrawalResults> Handle(AccountWithdrawalCommand command, CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation("Deposit transaction process started.");

                //check account
                BalanceInquiryModel acctBalance = new BalanceInquiryModel();
                acctBalance = await _accountService.BalanceInquiry(command.AcctId);

                if (acctBalance == null)
                {
                    return(new AccountWithdrawalResults
                    {
                        StatusCode = Convert.ToInt32(HttpStatusCode.OK),
                        Message = Convert.ToString(HttpStatusCode.OK),
                        MessageDetails = ManageAccountStatus.InvalidAccountNumber
                    });
                }

                if (command.TransactionAmount > acctBalance.AvailableBalance)
                {
                    return(new AccountWithdrawalResults
                    {
                        StatusCode = Convert.ToInt32(HttpStatusCode.OK),
                        Message = Convert.ToString(HttpStatusCode.OK),
                        MessageDetails = ManageAccountStatus.InsufficientFunds
                    });
                }

                AccountWithdrawalModel acctWithdrawal = new AccountWithdrawalModel();

                acctWithdrawal.AcctId            = command.AcctId;
                acctWithdrawal.TransactionType   = command.TransactionType;
                acctWithdrawal.TransactionAmount = command.TransactionAmount;

                await _accountService.AccountWithdrawal(acctWithdrawal);

                return(new AccountWithdrawalResults
                {
                    StatusCode = Convert.ToInt32(HttpStatusCode.OK),
                    Message = Convert.ToString(HttpStatusCode.OK),
                    MessageDetails = ManageAccountStatus.WithdrawalSuccess,
                    TranId = acctWithdrawal.TranId
                });
            }
            catch (Exception ex)
            {
                _logger.LogError("Error saving withdrawal transaction : {ExceptionMessage}", ex.ToString());

                return(new AccountWithdrawalResults
                {
                    StatusCode = Convert.ToInt32(HttpStatusCode.InternalServerError),
                    Message = Convert.ToString(HttpStatusCode.InternalServerError),
                    MessageDetails = ManageAccountStatus.WithdrawalFailed
                });
            }
        }