Example #1
0
        public async ValueTask <ActionResult <long> > CreateWithdrawTransaction2([FromBody] AuthInputModel authInput)
        {
            if (authInput.Pin.Length != 6)
            {
                BadRequest("PIN not entered or incorrect number of characters entered");
            }
            var tmp = await _operation.GetOperationById(authInput.Id);

            var operationModel = tmp.Data;
            var accountId      = operationModel.AccountId;

            if (_authentication.ValidateTwoFactorPIN(accountId, authInput.Pin) == true)
            {
                if (operationModel.IsCompleted == false)
                {
                    await _operation.CompletedOperation(authInput.Id);

                    var transactionModel = _mapper.Map <TransactionInputModel>(operationModel);
                    var currencyId       = await _repo.GetCurrencyByAccountId(transactionModel.AccountId);

                    transactionModel.CurrencyId = currencyId.Data;
                    var restRequest = new RestRequest("transaction/withdraw", Method.POST, DataFormat.Json);
                    restRequest.AddJsonBody(transactionModel);
                    var result = await _restClient.ExecuteAsync <long>(restRequest);

                    string code = Convert.ToString((CurrenciesCode)transactionModel.CurrencyId.Value);
                    _logger.Info($"Create new WithdrawTransaction for Account [{transactionModel.AccountId}] " +
                                 $"{transactionModel.Amount} {code}");
                    return(MakeResponse(result));
                }
                return(Ok("The operation was performed"));
            }
            return(BadRequest("Incorrect PIN entered"));
        }