public FileResult GetCurrencyCsv(GetCurrencyRequest request) { var Response = new GetCurrencyResponse() { CurrencyList = new List <Currency>() }; var res = request.GetWebData(); if (!res.Success) { Response.Success = res.Success; Response.ErrorCode = res.ErrorCode; Response.ErrorDescription = res.ErrorDescription; } var sortedData = res.CurrencyList.SortAndFilterData(request); var sb = new StringBuilder(); sb.AppendLine("crossOrder" + ";" + "kod" + ";" + "currencyCode" + ";" + "unit" + ";" + "isim" + ";" + "currencyName" + ";" + "forexBuying" + ";" + "forexSelling" + ";" + "banknoteBuying" + ";" + "banknoteSelling" + ";" + "crossRateUSD" + ";" + "crossRateOther"); foreach (var data in sortedData) { sb.AppendLine(data.CrossOrder + ";" + data.Kod + ";" + data.CurrencyCode + ";" + data.Unit + ";" + data.Isim + ";" + data.CurrencyName + "," + data.ForexBuying + ";" + data.ForexSelling + ";" + data.BanknoteBuying + ";" + data.BanknoteSelling + ";" + data.CrossRateUSD + ";" + data.CrossRateOther); } return(File(new UTF8Encoding().GetBytes(sb.ToString()), "text/csv", "export.csv")); }
public HttpResponseMessage GetCurrencies() { GetCurrencyResponse response = userService.GetCurrencies(new GetCurrencyRequest() { }); return(Request.BuildResponse(response)); }
public void GetCurrencyTest(string currency, bool authorizedUser) { GetCurrencyResponse result = client.GetCurrencyAsync(currency, authorizedUser).Result; string strret = JsonConvert.SerializeObject(result, Formatting.Indented); Console.WriteLine(strret); Assert.Equal(200, result.code); }
public JsonResult GetCurrencies() { GetCurrencyResponse response = userService.GetCurrencies(new GetCurrencyRequest() { }); return(Json(new { success = true, response = response.Currencies }, JsonRequestBehavior.AllowGet)); }
public GetCurrencyResponse GetCurrency(GetCurrencyRequest request) { GetCurrencyResponse Response = new GetCurrencyResponse() { CurrencyList = new List <Currency>() }; var res = request.GetWebData(); if (!res.Success) { Response.Success = res.Success; Response.ErrorCode = res.ErrorCode; Response.ErrorDescription = res.ErrorDescription; } var sortedData = res.CurrencyList.SortAndFilterData(request); Response.CurrencyList = sortedData; return(Response); }
public static GetCurrencyResponse GetWebData(this GetCurrencyRequest request) { GetCurrencyResponse Response = new GetCurrencyResponse() { CurrencyList = new List <Currency>() }; try { string url = "https://www.tcmb.gov.tr/kurlar/today.xml"; Response.CurrencyList = XDocument .Load(url) .Root .Elements("Currency") .Select(p => new Currency { CurrencyCode = p.Attribute("CurrencyCode").Value, CrossOrder = p.Attribute("CrossOrder").Value, Kod = p.Attribute("Kod").Value, Unit = (string)p.Element("Unit"), Isim = (string)p.Element("Isim"), CurrencyName = (string)p.Element("CurrencyName"), ForexBuying = (decimal?)(string.IsNullOrEmpty((string)p.Element("ForexBuying")) ? null : p.Element("ForexBuying")), ForexSelling = (decimal?)(string.IsNullOrEmpty((string)p.Element("ForexSelling")) ? null : p.Element("ForexSelling")), BanknoteBuying = (decimal?)(string.IsNullOrEmpty((string)p.Element("BanknoteBuying")) ? null : p.Element("BanknoteBuying")), BanknoteSelling = (decimal?)(string.IsNullOrEmpty((string)p.Element("BanknoteSelling")) ? null : p.Element("BanknoteSelling")), CrossRateUSD = (decimal?)(string.IsNullOrEmpty((string)p.Element("CrossRateUSD")) ? null : p.Element("CrossRateUSD")), CrossRateOther = (decimal?)(string.IsNullOrEmpty((string)p.Element("CrossRateOther")) ? null : p.Element("CrossRateOther")) }) .ToList(); } catch (Exception ex) { Response.Success = false; Response.ErrorDescription = ex.Message; } return(Response); }