//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)); }
public IActionResult Index() { CurrencyRates cr = _currencyRateService.GetCurrencyRate(); return(View(cr)); }
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 }); }