Beispiel #1
0
        public async ValueTask <ActionResult <List <long> > > CreateTransferTransaction([FromBody] TransferInputModel transactionModel)
        {
            var checkingAccountId = await _repo.GetAccountById(transactionModel.AccountId);

            if (checkingAccountId.Data is null)
            {
                return(BadRequest("The account is not found"));
            }
            var checkingAccountIdReceiver = await _repo.GetAccountById(transactionModel.AccountIdReceiver);

            if (checkingAccountIdReceiver.Data is null)
            {
                return(BadRequest("The account of receiver is not found"));
            }
            if (transactionModel.Amount <= 0)
            {
                return(BadRequest("The amount is missing"));
            }
            var currencyId = await _repo.GetCurrencyByAccountId(transactionModel.AccountId);

            transactionModel.CurrencyId = currencyId.Data;
            var receiver = await _repo.GetCurrencyByAccountId(transactionModel.AccountIdReceiver);

            transactionModel.ReceiverCurrencyId = receiver.Data;
            var restRequest = new RestRequest("transaction/transfer", Method.POST, DataFormat.Json);

            restRequest.AddJsonBody(transactionModel);
            var result = await _restClient.ExecuteAsync <List <long> >(restRequest);

            string code = Convert.ToString((CurrenciesCode)transactionModel.CurrencyId.Value);

            _logger.Info($"Create new TransferTransaction from Account {transactionModel.AccountId} to Account {transactionModel.AccountIdReceiver}: " +
                         $"{transactionModel.Amount} {code}");
            return(MakeResponse(result));
        }
Beispiel #2
0
        public async ValueTask <ActionResult <AccountWithLeadOutputModel> > GetAccountById(long id)
        {
            DataWrapper <AccountDto> dataWrapper = await _repo.GetAccountById(id);

            return(MakeResponse(dataWrapper, _mapper.Map <AccountWithLeadOutputModel>));
        }