public async Task <IActionResult> Calculate([FromForm] CalculateValute calculateValue) { ViewData["cookie"] = "cal"; if (ModelState.IsValid && calculateValue.basiccurrencyinput != 0 && calculateValue.basiccurrencycode != "Choose..." && calculateValue.targetcurrencycode != "Choose...") { var result = await _calculatorService.ExchangeRateAsync(calculateValue); return(View("~/Views/Calculator/Index.cshtml", result)); } else if (calculateValue.basiccurrencyinput <= 0) { return(View("~/Views/Error/Index.cshtml", new ResultModel <object>() { Code = 404, Message = "you gave the wrong value" })); } return(View("~/Views/Calculator/Index.cshtml", new ResultModel <CalculateValute>() { Code = 300 })); }
public async Task <ResultModel <CalculateValute> > ExchangeRateAsync(CalculateValute calculateValute) { var actualyCurrency = await _exchangeRateService.CurrenciesAsync(default(DateTime), default(DateTime)); var targetCurrencyList = actualyCurrency.Result.ToList(); var targetCurrency = targetCurrencyList[0].rates; calculateValute.targetcurrency = targetCurrency.Where(a => a.code == calculateValute.targetcurrencycode) .Select(a => a.mid).First(); calculateValute.basiccurrency = targetCurrency.Where(a => a.code == calculateValute.basiccurrencycode) .Select(a => a.mid).First(); calculateValute.value = (calculateValute.basiccurrency * calculateValute.basiccurrencyinput) / calculateValute.targetcurrency; return(new ResultModel <CalculateValute>() { Code = 200, Message = null, Result = calculateValute }); }