示例#1
0
        static void Main(string[] args)
        {
            try
            {
                var service = new ZohoBooks();
                service.initialize("{authtoken}", "{organization id}");
                RecurringExpensesApi recurringExpensesApi = service.GetRecurringExpensesApi();
                var parameters = new Dictionary<object, object>();
                parameters.Add("recurrence_name_startswith", "h");
                var recurringExpenses = recurringExpensesApi.GetRecurringExpenses(parameters);
                var recExpId = recurringExpenses[0].recurring_expense_id;
                if (recurringExpenses != null)
                    foreach (var recurringExpense in recurringExpenses)
                        Console.WriteLine("{0},{1},{2}", recurringExpense.account_name, recurringExpense.total, recurringExpense.recurrence_name);
                var recurringExpense1 = recurringExpensesApi.Get(recExpId);
                if (recurringExpense1 != null)
                    Console.WriteLine("{0},{1},{2}", recurringExpense1.account_name, recurringExpense1.total, recurringExpense1.recurrence_name);
                var newRecurringExpenseInfo = new RecurringExpense()
                {
                    account_id = "{account id}",
                    paid_through_account_id = "{account id from which going to pay}",
                    recurrence_name = "rec name",
                    start_date = "2014-02-03",
                    recurrence_frequency = "months",
                    repeat_every = 2,
                    amount = 1000,
                };
                var newRecurringExpense = recurringExpensesApi.Create(newRecurringExpenseInfo);
                if (newRecurringExpense != null)
                    Console.WriteLine("{0},{1},{2}", newRecurringExpense.account_name, newRecurringExpense.total, newRecurringExpense.recurrence_name);
                var updateInfo = new RecurringExpense()
                {
                    recurrence_frequency = "weeks",
                    repeat_every = 4,

                };
                var updatedExpense = recurringExpensesApi.Update(recExpId, updateInfo);
                if (updatedExpense != null)
                    Console.WriteLine("{0},{1},{2}", updatedExpense.account_name, updatedExpense.total, updatedExpense.recurrence_name);
                var delRecurringExpense = recurringExpensesApi.Delete(recurringExpenses[3].recurring_expense_id);
                Console.WriteLine(delRecurringExpense);
                var stopRecurringExpense = recurringExpensesApi.Stop(recExpId);
                Console.WriteLine(stopRecurringExpense);
                var resumeRecurringExpense = recurringExpensesApi.Resume(recExpId);
                Console.WriteLine(resumeRecurringExpense);
                var childExpenses = recurringExpensesApi.GetExpensesCreated(recExpId, parameters);
                if (childExpenses != null)
                    foreach (var childExpense in childExpenses)
                        Console.WriteLine("{0},{1},{2}", childExpense.account_name, childExpense.total, childExpense.date);
                var comments = recurringExpensesApi.GetComments(recExpId);
                if (comments != null)
                    foreach (var comment in comments)
                        Console.WriteLine("{0},{1},{2}", comment.comment_id, comment.description, comment.commented_by);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
 /// <summary>
 /// Creates the new recurring expense.
 /// </summary>
 /// <param name="new_recurring_expense">The new_recurring_expense is the recurringExpense object with amount_id,paid_through_id,recurrence_name,star_date,recurrence_frequency,amount and repeat_every as mandatory attributes.</param>
 /// <returns>RecurringExpense object.</returns>
 public RecurringExpense Create(RecurringExpense new_recurring_expense)
 {
     string url = baseAddress;
     var json = JsonConvert.SerializeObject(new_recurring_expense);
     var jsonstring = new Dictionary<object, object>();
     jsonstring.Add("JSONString", json);
     var responce = ZohoHttpClient.post(url, getQueryParameters(jsonstring));
     return RecurringExpenseParser.getRecurringExpense(responce);
 }
 internal static RecurringExpense getRecurringExpense(HttpResponseMessage responce)
 {
     var recExp = new RecurringExpense();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("recurring_expense"))
     {
         recExp = JsonConvert.DeserializeObject<RecurringExpense>(jsonObj["recurring_expense"].ToString());
     }
     return recExp;
 }
 internal static RecurringExpenseList getRecurringExpenseList(HttpResponseMessage responce)
 {
     var recExpList = new RecurringExpenseList();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("recurring_expenses"))
     {
         var recExpArray = JsonConvert.DeserializeObject<List<object>>(jsonObj["recurring_expenses"].ToString());
         foreach(var recExpObj in recExpArray)
         {
             var recExp = new RecurringExpense();
             recExp = JsonConvert.DeserializeObject<RecurringExpense>(recExpObj.ToString());
             recExpList.Add(recExp);
         }
     }
     if (jsonObj.ContainsKey("page_context"))
     {
         var pageContext = new PageContext();
         pageContext = JsonConvert.DeserializeObject<PageContext>(jsonObj["page_context"].ToString());
         recExpList.page_context = pageContext;
     }
     return recExpList;
 }
 /// <summary>
 /// Updates the specified existing recurring expense .
 /// </summary>
 /// <param name="recurring_expense_id">The recurring_expense_id is the identifier of the recurrence expnse.</param>
 /// <param name="update_info">The update_info is the RecurringExpense object which contains the updation information.</param>
 /// <returns>RecurringExpense object.</returns>
 public RecurringExpense Update(string recurring_expense_id, RecurringExpense update_info)
 {
     string url = baseAddress + "/" + recurring_expense_id;
     var json = JsonConvert.SerializeObject(update_info);
     var jsonstring = new Dictionary<object, object>();
     jsonstring.Add("JSONString", json);
     var responce = ZohoHttpClient.put(url, getQueryParameters(jsonstring));
     return RecurringExpenseParser.getRecurringExpense(responce);
 }