예제 #1
0
 /// <summary>
 /// Create an exchange rate for the specified currency.
 /// </summary>
 /// <param name="currency_id">The currency_id is the identifier of the currency.</param>
 /// <param name="new_exchange_rate_info">The new_exchange_rate_info is the ExchangeRate object with effective_date and rate as mandatory attributes.</param>
 /// <returns>ExchangeRate object.</returns>
 public ExchangeRate CreateAnExchangeRate(string currency_id, ExchangeRate new_exchange_rate_info)
 {
     string url = baseAddress + "/currencies/" + currency_id + "/exchangerates";
     var json = JsonConvert.SerializeObject(new_exchange_rate_info);
     var jsonstring = new Dictionary<object, object>();
     jsonstring.Add("JSONString", json);
     var response = ZohoHttpClient.post(url, getQueryParameters(jsonstring));
     return CurrencyParser.getExchangeRate(response);
 }
 internal static ExchangeRate getExchangeRate(HttpResponseMessage response)
 {
     var rate = new ExchangeRate();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("exchange_rate"))
     {
         rate = JsonConvert.DeserializeObject<ExchangeRate>(jsonObj["exchange_rate"].ToString());
     }
     return rate;
 }
 internal static ExchangeRateList getExchangeRateList(HttpResponseMessage response)
 {
     var rateList = new ExchangeRateList();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("exchange_rates"))
     {
         var ratesArray = JsonConvert.DeserializeObject<List<object>>(jsonObj["exchange_rates"].ToString());
         foreach(var rateObj in ratesArray)
         {
             var rate = new ExchangeRate();
             rate = JsonConvert.DeserializeObject<ExchangeRate>(rateObj.ToString());
             rateList.Add(rate);
         }
     }
     if (jsonObj.ContainsKey("page_context"))
     {
         var pageContext = new PageContext();
         pageContext = JsonConvert.DeserializeObject<PageContext>(jsonObj["page_context"].ToString());
         rateList.page_context = pageContext;
     }
     return rateList;
 }
예제 #4
0
 static void Main(string[] args)
 {
     try
     {
         var service = new ZohoBooks();
         service.initialize("{authtoken}", "{organization id}");
         var currenciesApi = service.GetSettingsApi();
         var parameters = new Dictionary<object, object>();
        parameters.Add("filter_by", "Currencies.ExcludeBaseCurrency");
         var currenciesList = currenciesApi.GetCurrencies(parameters);
         var currencies = currenciesList;
         var currencyId = currencies[0].currency_id;
         foreach (var currency in currencies)
             Console.WriteLine("Id:{0},\ncode:{1},\nname:{2},\nsymbol:{3}\nFormat:{4}\n", currency.currency_id, currency.currency_code, currency.currency_name, currency.currency_symbol, currency.currency_format);
         var currency1 = currenciesApi.GetACurrency(currencyId);
         Console.WriteLine("Id:{0},\ncode:{1},\nname:{2},\nsymbol:{3}\nFormat:{4}\n", currency1.currency_id, currency1.currency_code, currency1.currency_name, currency1.currency_symbol, currency1.currency_format);
         var newCurrencyInfo = new Currency()
         {
             currency_code = "JPY",
             currency_symbol = "%",
             currency_format = "1,234,567.89"
         };
         var newCurrency = currenciesApi.CreateCurrency(newCurrencyInfo);
         Console.WriteLine("Id:{0},\ncode:{1},\nname:{2},\nsymbol:{3}\nFormat:{4}\n", newCurrency.currency_id, newCurrency.currency_code, newCurrency.currency_name, newCurrency.currency_symbol, newCurrency.currency_format);
         var updateInfo = new Currency()
         {
             currency_symbol = "&"
         };
         var updatedCurrncy = currenciesApi.UpdateCurrency(newCurrency.currency_id, updateInfo);
         Console.WriteLine("Id:{0},\ncode:{1},\nname:{2},\nsymbol:{3}\nFormat:{4}\n", updatedCurrncy.currency_id, updatedCurrncy.currency_code, updatedCurrncy.currency_name, updatedCurrncy.currency_symbol, updatedCurrncy.currency_format);
         var deletemsg = currenciesApi.DeleteCurrency(updatedCurrncy.currency_id);
         Console.WriteLine(deletemsg);
         var ErParameters = new Dictionary<object, object>();
         var exchangeratesList = currenciesApi.GetExchangeRates("71917000000000097", ErParameters);
         var exchangerates = exchangeratesList;
         var exchangeRateId = exchangerates[0].exchange_rate_id;
         foreach (var exchangerate in exchangerates)
             Console.WriteLine("ExchangerateId:{0},\ncurrency Id:{1},Currency Code:{2},\nRate:{3}\n",exchangerate.exchange_rate_id,exchangerate.currency_id,exchangerate.currency_code,exchangerate.rate);
         var exchngerate = currenciesApi.GetAnExchangeRate("71917000000000097", exchangeRateId);
         Console.WriteLine("ExchangerateId:{0},\ncurrency Id:{1},\nCurrency Code:{2},\nRate:{3}\n", exchngerate.exchange_rate_id, exchngerate.currency_id, exchngerate.currency_code, exchngerate.rate);
         var newExchangerateInfo = new ExchangeRate()
         {
             effective_date="2014-05-14",
             rate=31,
         };
         var newExchangerate = currenciesApi.CreateAnExchangeRate("71917000000000097", newExchangerateInfo);
         Console.WriteLine("ExchangerateId:{0},\ncurrency Id:{1},\nCurrency Code:{2},\nRate:{3}\n", newExchangerate.exchange_rate_id, newExchangerate.currency_id, newExchangerate.currency_code, newExchangerate.rate);
         var updateinfo = new ExchangeRate()
         {
             rate = 40,
         };
         var updatedExchangerate = currenciesApi.UpdateAnExchangeRate("71917000000000097", newExchangerate.exchange_rate_id, updateinfo);
         Console.WriteLine("ExchangerateId:{0},\ncurrency Id:{1},\nCurrency Code:{2},\nRate:{3}\n", updatedExchangerate.exchange_rate_id, updatedExchangerate.currency_id, updatedExchangerate.currency_code, updatedExchangerate.rate);
         var deleteMsg = currenciesApi.DeleteAnExchangeRate("71917000000000097", updatedExchangerate.exchange_rate_id);
         Console.WriteLine(deleteMsg);
     }
     catch(Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey();
 }