internal static Estimate getEstimate(HttpResponseMessage responce)
 {
     var estimate = new Estimate();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("estimate"))
     {
         estimate = JsonConvert.DeserializeObject<Estimate>(jsonObj["estimate"].ToString());
     }
     return estimate;
 }
 internal static EstimateList getEstimateList(HttpResponseMessage responce)
 {
     var estimateList = new EstimateList();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("estimates"))
     {
         var estimatesArray = JsonConvert.DeserializeObject<List<object>>(jsonObj["estimates"].ToString());
         foreach(var estimateObj in estimatesArray)
         {
             var estimate = new Estimate();
             estimate = JsonConvert.DeserializeObject<Estimate>(estimateObj.ToString());
             estimateList.Add(estimate);
         }
     }
     if (jsonObj.ContainsKey("page_context"))
     {
         var pageContext = new PageContext();
         pageContext = JsonConvert.DeserializeObject<PageContext>(jsonObj["page_context"].ToString());
         estimateList.page_context = pageContext;
     }
     return estimateList;
 }
 /// <summary>
 /// Create an estimate for your customer.
 /// </summary>
 /// <param name="new_estimate_info">The new_estimate_info is the Estimate object with contact_id and item_name are mandatory attributes.</param>
 /// <param name="parameters">The parameters is the dictionary object which contains the parameters in the key,value pairs.<br></br>The parameters are listed below<br></br>
 /// <table>
 /// <tr><td>send</td><td>Send the estimate to the contact person(s) associated with the estimate.<br></br>Allowed Values: <i>true</i> and <i>false</i></td></tr>
 /// <tr><td>ignore_auto_number_generation</td><td>Ignore auto estimate number generation for this estimate. This mandates the estimate number.<br></br>Allowed Values: <i>true</i> and <i>false</i></td></tr>
 /// </table>
 /// </param>
 /// <returns>Estimate object.</returns>
 public Estimate Create(Estimate new_estimate_info, Dictionary<object, object> parameters)
 {
     string url = baseAddress;
     var json = JsonConvert.SerializeObject(new_estimate_info);
     parameters.Add("JSONString", json);
     var responce = ZohoHttpClient.post(url, getQueryParameters(parameters));
     return EstimateParser.getEstimate(responce);
 }
 /// <summary>
 /// Update an existing estimate. To delete a line item just remove it from the line_items list.
 /// </summary>
 /// <param name="estimate_id">The estimate_id is the identifier of the estimate.</param>
 /// <param name="update_info">The update_info is the Estimate object which contains the update details.</param>
 /// <param name="parameters">The parameters is the Dictionary object.<br></br>The possible parameters are <br></br>
 /// <table><tr><td>ignore_auto_number_generation</td><td>Ignore auto estimate number generation for this estimate. This mandates the estimate number.<br></br>Allowed Values: <i>true</i> and <i>false</i></td></tr></table>
 /// </param>
 /// <returns>Estimate object.</returns>
 public Estimate Update(string estimate_id, Estimate update_info, Dictionary<object, object> parameters)
 {
     string url = baseAddress + "/" + estimate_id;
     var json = JsonConvert.SerializeObject(update_info);
     parameters.Add("JSONString", json);
     var responce = ZohoHttpClient.put(url, getQueryParameters(parameters));
     string responceContent = responce.Content.ReadAsStringAsync().Result;
     return EstimateParser.getEstimate(responce);
 }
        static void Main(string[] args)
        {
            try
            {
                var service = new ZohoBooks();
                service.initialize("{authtoken}", "{organisation id}");
                EstimatesApi estimateApi = service.GetEstimatesApi();
                var parameters = new Dictionary<object, object>();
                 var estimatesList = estimateApi.GetEstimates(parameters);
                 var estimates = estimatesList;
                 var estimateId = estimates[0].estimate_id;
                 var customerId = estimates[0].customer_id;
                 var contactPersns = estimates[0].contact_persons;
                 if (estimates != null)
                     foreach (var estimate in estimates)
                         Console.WriteLine("{0},{1},{2}", estimate.estimate_id, estimate.customer_name, estimate.estimate_number);
                 var parameters1 = new Dictionary<object, object>();
                  parameters1.Add("send",true);
                  var newEstmt = new Estimate()
                  {
                      customer_id = customerId,
                      template_id = "{template id}",
                      reference_number = "QRT-",
                      date = "2014-03-10",
                      expiry_date = "2014-03-24",
                      exchange_rate = 1.0,
                      discount = 0.0,
                      is_discount_before_tax = true,
                      discount_type = "item_level",
                      salesperson_name = "John Michael",
                      line_items = new List<LineItem>()
                          {
                                  new LineItem(){
                                  name="Premium Plan - Web hosting",
                                  description="10 GB Space, 300 GB Transfer 100 Email Accounts 10 MySQL Databases",
                                  rate=2500,
                                  item_order=0,
                                  quantity=1.0,
                                  discount="0.0",

                                  },
                          },
                      notes = "Looking forward for your business.",
                      terms = "Terms and conditions apply.",
                      shipping_charge = 0.0,
                      adjustment = 0.0,
                      adjustment_description = "Adjustment"
                  };
                  var newEstimate = estimateApi.Create(newEstmt, parameters1);
                  if(newEstimate!=null)
                  {
                      Console.WriteLine("The new Estimate is created with the api call for the amount {0} which is having the following properties\n",newEstimate.total);
                      Console.WriteLine("Estimate Id:{0}\n,Estimate number:{1},\n status:{2},\n",newEstimate.estimate_id,newEstimate.estimate_number,newEstimate.status);
                      var billto = newEstimate.billing_address;
                      Console.WriteLine("To:{0},{1},{2},{3},{4}", newEstimate.customer_name, billto.address, billto.city, billto.country, billto.zip);
                      var items = newEstimate.line_items;
                      Console.WriteLine("\n Items details:\n");
                      foreach (var item in items)
                          Console.WriteLine("\n name: {0},\nCost: {1},\n Quantity :{2}", item.name, item.rate, item.quantity);

                  }
                  var parameters2 = new Dictionary<object, object>();
                var updateInfo = new Estimate()
                {

                     reference_number="2197",

               };
                 var updatedEst =estimateApi.Update(estimateId, updateInfo,parameters2);
                if(updatedEst!=null)
                    Console.WriteLine("{0},{1},{2}", updatedEst.estimate_number, updatedEst.reference_number, updatedEst.exchange_rate);
                var delmsg = estimateApi.Delete(estimates[2].estimate_id);
                Console.WriteLine(delmsg);
                var status = estimateApi.MarkAsSent(estimateId);
                Console.WriteLine(status);
                var status1 = estimateApi.MarkAsAccepted(estimateId);
                Console.WriteLine(status);
                var status2 = estimateApi.MarkAsDeclined(estimateId);
                Console.WriteLine(status);
                var emailDetails = new EmailNotification()
                {
                    to_mail_ids = new List<string>(){
                    "*****@*****.**",},
                    subject = "estimate email",
                    body = "est"
                };
                var emailEst = estimateApi.SendEmail(estimateId, emailDetails, new string[] { @"F:\error.png", @"F:\error.png" });
                Console.WriteLine(emailEst);
                var estIds = new Dictionary<object, object>();
                estIds.Add("estimate_ids", estimates[1].estimate_id + "," + estimates[2]);
                var emailests = estimateApi.EmailEstimates(estIds);
                Console.WriteLine(emailests);
                var emailContent = estimateApi.GetEmailContent(estimateId, null);
                Console.WriteLine("{0},{1},{2}", emailContent.body, emailContent.file_name, emailContent.subject);
                var export = estimateApi.BulkExport(estIds);
                Console.WriteLine(export);
                var print = estimateApi.BulkPrint(estIds);
                Console.WriteLine(print);
                var updateinfo3 = new Address()
                {
                    address = "31",
                    city = "chennai"
                };
                var update = estimateApi.UpdateBillingAddress(estimateId, updateinfo3);
                Console.WriteLine(update);
                var updateinfo2 = new Address()
                {
                    state="TamilNadu"
                };
                var shipaddrUpdate = estimateApi.UpdateShippingAddress(estimateId, updateinfo2);
                Console.WriteLine(shipaddrUpdate);
                var estTemplatesList = estimateApi.GetTemplates();
                var templates = estTemplatesList;
                foreach (var estTemplate in templates)
                    Console.WriteLine("{0},{1},{2}", estTemplate.template_id, estTemplate.template_name, estTemplate.template_type);

                var updateTemplate = estimateApi.UpdateTemplate(estimateId, templates[1].template_id);
                Console.WriteLine(updateTemplate);
                var commentsList = estimateApi.GetComments(estimateId);
                var comments = commentsList;
                foreach (var comment in comments)
                    Console.WriteLine("{0},{1},{2}",comment.comment_id,comment.description,comment.commented_by);
                var newCommentInfo = new Comment()
                {
                    description = "added manually"
                };
                var newComment = estimateApi.AddComment(estimateId, newCommentInfo);
                Console.WriteLine(newComment);
                var updateInfo1 = new Comment()
                {
                    description = "edited comment"
                };
                var updated = estimateApi.UpdateComment(estimateId, comments[2].comment_id, updateInfo1);
                Console.WriteLine("{0},{1},{2}", updated.comment_id, updated.description, updated.commented_by);
                var deleteMsg = estimateApi.DeleteComment(estimateId, comments[4].comment_id);
                Console.WriteLine(deleteMsg);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }