public CurrencyModels GetCurrencyCurrent() { CurrencyModels obj = new CurrencyModels(); try { GetCurrencyRequest paraBody = new GetCurrencyRequest(); paraBody.IsActive = true; NSLog.Logger.Info("GetCurrencyCurrent Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CurrencyAPIGetList, null, paraBody); NSLog.Logger.Info("GetCurrencyCurrent Response", paraBody); dynamic data = result.Data; var lstDataRaw = data["ListCurrency"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); List <CurrencyModels> listData = JsonConvert.DeserializeObject <List <CurrencyModels> >(lstObject); if (listData != null && listData.Any()) { obj = listData.FirstOrDefault(); } return(obj); } catch (Exception e) { NSLog.Logger.Error("GetCurrencyCurrent_Fail", e); return(obj); } }
public CurrencyDTO GetDetail(string ID) { CurrencyDTO model = new CurrencyDTO(); try { GetCurrencyRequest paraBody = new GetCurrencyRequest(); paraBody.ID = ID; NSLog.Logger.Info("Currency Get Detail Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CurrencyAPIGetList, null, paraBody); NSLog.Logger.Info("Currency Get Detail Response", paraBody); dynamic data = result.Data; var lstDataRaw = data["ListCurrency"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); model = JsonConvert.DeserializeObject <List <CurrencyDTO> >(lstObject)[0]; NSLog.Logger.Info("Currency_GetDetail", model); return(model); } catch (Exception e) { NSLog.Logger.Error("Currency_GetDetail_Fail", e); return(model); } }
/// <summary> /// Get the currency async /// </summary> /// <returns>Symbol</returns> public async Task <CallResult <HitBTCCurrency> > GetCurrencyAsync(string id) { var req = new GetCurrencyRequest(NextId(), id); var result = await Query <HitBTCSocketResponse <HitBTCCurrency> >(req, false).ConfigureAwait(false); return(new CallResult <HitBTCCurrency>(result.Data?.Result, result.Error)); }
public List <CurrencyModels> GetListData() { List <CurrencyModels> listData = new List <CurrencyModels>(); try { GetCurrencyRequest paraBody = new GetCurrencyRequest(); NSLog.Logger.Info("Currency Get ListData Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CurrencyAPIGetList, null, paraBody); NSLog.Logger.Info("Currency Get List Data Response", paraBody); dynamic data = result.Data; var lstDataRaw = data["ListCurrency"]; var lstObject = JsonConvert.SerializeObject(lstDataRaw); listData = JsonConvert.DeserializeObject <List <CurrencyModels> >(lstObject); NSLog.Logger.Info("CurrencyGetListData", listData); return(listData); } catch (Exception e) { NSLog.Logger.Error("CurrencyGetListData_Fail", e); return(listData); } }
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 void Test1() { GetCurrencyRequest req = new GetCurrencyRequest() { CurrencyType = null, OrderByType = OrderByEnums.ASCENDING, SortCostType = SortCostEnums.ForexBuying }; TcmbController cont = new TcmbController(_logger); Assert.True(cont.GetCurrency(req).Success); }
public void Test2() { GetCurrencyRequest req = new GetCurrencyRequest() { CurrencyType = null, OrderByType = OrderByEnums.ASCENDING, SortCostType = SortCostEnums.ForexBuying }; TcmbController cont = new TcmbController(_logger); var result = cont.GetCurrencyCsv(req); Assert.NotNull(result); Assert.NotNull(result.FileDownloadName); }
/// <summary> /// Gets all currency exchanges registered. This should have parameters to filter data /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override async Task <GetCurrencyReply> GetCurrencyExchange(GetCurrencyRequest request, ServerCallContext context) { var exchanges = await _currencyExchangeQuery.RunAsync(); // TODO: This should be moved to a translator var items = exchanges.Select(c => new CurrencyExchangeItem() { BaseCurrencyName = c.BaseCurrencyCode, BuyRate = (float)c.BuyRate, CurrencyName = c.CurrencyCode, SellRate = (float)c.SellRate }); var toReturn = new GetCurrencyReply { Items = { items } }; return(toReturn); }
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); }
public static List <Currency> SortAndFilterData(this List <Currency> CurrencyList, GetCurrencyRequest request) { try { if (!string.IsNullOrEmpty(request.CurrencyType)) { CurrencyList = CurrencyList.FindAll(x => x.CurrencyCode == request.CurrencyType); } switch (request.SortCostType) { case SortCostEnums.BanknoteBuying: switch (request.OrderByType) { case OrderByEnums.DESCENDING: CurrencyList = CurrencyList .Where(x => x.BanknoteBuying != null) .OrderByDescending(x => x.BanknoteBuying) .ToList(); break; case OrderByEnums.ASCENDING: CurrencyList = CurrencyList .Where(x => x.BanknoteBuying != null) .OrderBy(x => x.BanknoteBuying) .ToList(); break; default: break; } break; case SortCostEnums.BanknoteSelling: switch (request.OrderByType) { case OrderByEnums.DESCENDING: CurrencyList = CurrencyList .Where(x => x.BanknoteSelling != null) .OrderByDescending(x => x.BanknoteSelling) .ToList(); break; case OrderByEnums.ASCENDING: CurrencyList = CurrencyList .Where(x => x.BanknoteSelling != null) .OrderBy(x => x.BanknoteSelling) .ToList(); break; default: break; } break; case SortCostEnums.ForexBuying: switch (request.OrderByType) { case OrderByEnums.DESCENDING: CurrencyList = CurrencyList .Where(x => x.ForexBuying != null) .OrderByDescending(x => x.ForexBuying) .ToList(); break; case OrderByEnums.ASCENDING: CurrencyList = CurrencyList .Where(x => x.ForexBuying != null) .OrderBy(x => x.ForexBuying) .ToList(); break; default: break; } break; case SortCostEnums.ForexSelling: switch (request.OrderByType) { case OrderByEnums.DESCENDING: CurrencyList = CurrencyList .Where(x => x.ForexSelling != null) .OrderByDescending(x => x.ForexSelling) .ToList(); break; case OrderByEnums.ASCENDING: CurrencyList = CurrencyList .Where(x => x.ForexSelling != null) .OrderBy(x => x.ForexSelling) .ToList(); break; default: break; } break; default: break; } } catch (Exception ex) { throw ex; } return(CurrencyList); }