public async Task RightDownExchange(HistoryRowDto rowDto) { if (!rowDto.ToAmount.HasValue) { throw new ArgumentException(); } //var from = await _dbContext.Currencies.FindAsync(rowDto.FromCurrency); //var to = await _dbContext.Currencies.FindAsync(rowDto.ToCurrency); var historyRow = new HistoryRow { FromAmount = rowDto.FromAmount, ToAmount = rowDto.ToAmount.Value, FromCurrency = rowDto.FromCurrency, ToCurrency = rowDto.ToCurrency }; await _dbContext.History.AddAsync(historyRow); await _dbContext.SaveChangesAsync(); }
public async Task <ActionResult <decimal> > Get([FromQuery] HistoryRowDto rowDto) { decimal toAmount; try { var rate = await GetRatesFromExternalApi(rowDto.FromCurrency, rowDto.ToCurrency); toAmount = rowDto.FromAmount * rate.rates[rowDto.ToCurrency]; } catch { return(BadRequest()); } rowDto.ToAmount = toAmount; await _historyService.RightDownExchange(rowDto); return(toAmount); }