コード例 #1
0
        //TODO use currencies int this method instead of currencynames
        public decimal Exchange(string currencyIsoNameFrom, string currencyIsoNameTo, decimal amount)
        {
            //DKK
            var baseCurrency = _currencyRateService.GetBaseCurrency();

            var currencyFrom = _currencyRateService.GetCurrencyRate(currencyIsoNameFrom);
            var currencyTo   = _currencyRateService.GetCurrencyRate(currencyIsoNameTo);

            IExchangeCase exchangeCase = new ExchangeCaseFactory().GetExchangeCase(currencyFrom, currencyTo, baseCurrency);

            return(exchangeCase.Exchange(amount));
        }
コード例 #2
0
        public IActionResult Index()
        {
            CurrencyRates cr = _currencyRateService.GetCurrencyRate();

            return(View(cr));
        }
コード例 #3
0
        public async Task <TransferMoneyBetweenAccountResponse> TransferMoneyBetweenAccountAsync(TransferMoneyBetweenAccountRequest request)
        {
            var currencyRate = await currencyRateService.GetCurrencyRate(new CurrencyRateRequest
            {
                FromCurrencyId = request.FromCurrencyId,
                ToCurrencyId   = request.ToCurrencyId
            });

            if (!currencyRate.IsSuccess)
            {
                return(new TransferMoneyBetweenAccountResponse
                {
                    Error = NoCurrencyRateFound,
                    IsSuccess = false
                });
            }

            var withdrawPayment = await WithdrawPaymentAsync(new WithdrawPaymentRequest
            {
                CurrencyId = request.FromCurrencyId,
                UserId     = request.UserId,
                Amount     = request.Amount
            });


            if (!withdrawPayment.IsSuccess)
            {
                return(new TransferMoneyBetweenAccountResponse
                {
                    Error = FailedToRaiseMoney,
                    IsSuccess = false
                });
            }

            var addPayment = await AddPaymentAsync(new AddPaymentRequest
            {
                UserId     = request.UserId,
                CurrencyId = request.ToCurrencyId,
                Amount     = request.Amount *currencyRate.CurrencyRate
            });

            if (!addPayment.IsSuccess)
            {
                await AddPaymentAsync(new AddPaymentRequest
                {
                    Amount     = request.Amount,
                    CurrencyId = request.FromCurrencyId,
                    UserId     = request.UserId
                });

                return(new TransferMoneyBetweenAccountResponse
                {
                    Error = FailedToRaiseMoney,
                    IsSuccess = false
                });
            }

            return(new TransferMoneyBetweenAccountResponse
            {
                IsSuccess = true
            });
        }