public JsonResult Przelicz(decimal kwota, string code) { FixerAPIModel model = GetDataFixer(code); decimal rate = model.rates["PLN"]; decimal result = kwota * rate; return(Json(new { kwota = result }, JsonRequestBehavior.AllowGet)); }
private FixerAPIModel GetDataFixer(string kod) { using (WebClient client = new WebClient()) { var url = "https://api.fixer.io/latest"; if (kod != null) { url = url + "?base=" + kod; } var stream = client.OpenRead(url); StreamReader reader = new StreamReader(stream); string s = reader.ReadToEnd(); FixerAPIModel model = JsonConvert.DeserializeObject <FixerAPIModel>(s); stream.Close(); return(model); } }
// GET: Waluty public ActionResult Index(string kod) { FixerAPIModel model = GetDataFixer(kod); return(View(model)); }