Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     try
     {
         var service = new ZohoBooks();
         service.initialize("{authtoken}", "{organization id}");
         var organizationApi = service.GetOrganizationsApi();
        var organizationsList = organizationApi.GetOrganizations();
        var organizations = organizationsList;
        var organizationId = organizations[0].organization_id;
         foreach (var organization in organizations)
             Console.WriteLine("Organization Id:{0},\n name:{1},\n contact name:{2},\n email:{3}", organization.organization_id, organization.name, organization.contact_name, organization.email);
         var organization1 = organizationApi.Get(organizationId);
         Console.WriteLine("Organization Id:{0},\n name:{1},\n contact name:{2},\n email:{3}\n addr:{4}\n", organization1.organization_id, organization1.name, organization1.contact_name, organization1.email,organization1.org_address);
         var addr = organization1.address;
         Console.WriteLine("Address:{0},{1},{2}",addr.city,addr.state,addr.country);
         var newOrganizationInfo = new Organization()
         {
             name="org3",
             currency_code="INR",
             time_zone = "IST",
             address=new Address(){country="India"}
         };
         var newOrganization = organizationApi.Create(newOrganizationInfo);
         Console.WriteLine("Organization Id:{0},\n name:{1},\n contact name:{2},\n email:{3}", newOrganization.organization_id, newOrganization.name, newOrganization.contact_name, newOrganization.email);
         var updateInfo = new Organization()
         {
             name="Org2",
             address = new Address()
             {
                 city="city",
                 state="state",
                 country="India"
             },
         };
         var updatedOrg = organizationApi.Upadte(organizationId, updateInfo);
         Console.WriteLine("Organization Id:{0},\n name:{1},\n contact name:{2},\n email:{3}\n addr:{4}\n", updatedOrg.organization_id, updatedOrg.name, updatedOrg.contact_name, updatedOrg.email, updatedOrg.org_address);
         var address = updatedOrg.address;
         Console.WriteLine("Address:{0},{1},{2}", address.city, address.state, address.country);
         var new_address_info = new Address()
         {
             attention="hari",
         };
         var newAddress = organizationApi.AddOrganizationAddress(new_address_info);
         var update_addr_info = new Address()
         {
             attention = "krishna"
         };
         var updatedAddress = organizationApi.UpdateOrganizationAddress(newAddress.organization_address_id, update_addr_info);
     }
     catch(Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey();
 }
 /// <summary>
 /// Create an organization.
 /// </summary>
 /// <param name="oranization_info">The oranization_info is the Organization object with name,currency_code and time_zone as mandatory attributes.</param>
 /// <returns>Organization object.</returns>
 public Organization Create(Organization oranization_info)
 {
     string url = baseAddress;
     var json = JsonConvert.SerializeObject(oranization_info);
     var jsonstring = new Dictionary<object, object>();
     jsonstring.Add("JSONString", json);
     var responce = ZohoHttpClient.post(url, getQueryParameters(jsonstring));
     Console.WriteLine(responce.Content.ReadAsStringAsync().Result);
     return OrganizationParser.getOrganization(responce);
 }
 internal static Organization getOrganization(HttpResponseMessage responce)
 {
     var organization = new Organization();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("organization"))
     {
         organization = JsonConvert.DeserializeObject<Organization>(jsonObj["organization"].ToString());
     }
     return organization;
 }
 /// <summary>
 /// Update the details of an organization.
 /// </summary>
 /// <param name="organization_id">The organization_id is the identifier of the organization.</param>
 /// <param name="update_info">The update_info is the Organization object which contains the updation information.</param>
 /// <returns>Organization object.</returns>
 public Organization Upadte(string organization_id, Organization update_info)
 {
     string url = baseAddress + "/" + organization_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 OrganizationParser.getOrganization(responce);
 }
 internal static OrganizationList getOrganizationList(HttpResponseMessage response)
 {
     var organizationList = new OrganizationList();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("organizations"))
     {
         var organizationArray = JsonConvert.DeserializeObject<List<object>>(jsonObj["organizations"].ToString());
         foreach(var organizationObj in organizationArray)
         {
             var organization = new Organization();
             organization = JsonConvert.DeserializeObject<Organization>(organizationObj.ToString());
             organizationList.Add(organization);
         }
     }
     return organizationList;
 }