private JObject GetZCRMOrgTaxAsJSON(ZCRMOrgTax tax) { JObject taxJSON = new JObject { { "name", tax.Name }, { "id", tax.Id }, { "display_label", tax.DisplayName }, { "value", tax.Value }, }; return(taxJSON); }
public BulkAPIResponse <ZCRMOrgTax> CreateTaxes(List <ZCRMOrgTax> taxes) { if (taxes.Count > 100) { throw new ZCRMException(APIConstants.API_MAX_RECORDS_MSG); } try { requestMethod = APIConstants.RequestMethod.POST; urlPath = "org/taxes"; JObject requestBodyObject = new JObject(); JArray dataArray = new JArray(); foreach (ZCRMOrgTax tax in taxes) { dataArray.Add(GetZCRMOrgTaxAsJSON(tax)); } requestBodyObject.Add("taxes", dataArray); requestBody = requestBodyObject; BulkAPIResponse <ZCRMOrgTax> response = APIRequest.GetInstance(this).GetBulkAPIResponse <ZCRMOrgTax>(); List <ZCRMOrgTax> createdTaxes = new List <ZCRMOrgTax>(); List <EntityResponse> responses = response.BulkEntitiesResponse; foreach (EntityResponse entityResponse in responses) { if (entityResponse.Status.Equals(APIConstants.CODE_SUCCESS)) { JObject responseData = entityResponse.ResponseJSON; JObject responseDetails = (JObject)responseData[APIConstants.DETAILS]; ZCRMOrgTax tax = GetZCRMOrgTax(responseDetails); createdTaxes.Add(tax); entityResponse.Data = tax; } else { entityResponse.Data = null; } } response.BulkData = createdTaxes; return(response); } catch (Exception e) when(!(e is ZCRMException)) { ZCRMLogger.LogError(e); throw new ZCRMException(APIConstants.SDK_ERROR, e); } }
private ZCRMOrgTax GetZCRMOrgTax(JObject taxDetails) { ZCRMOrgTax tax = ZCRMOrgTax.GetInstance((long)taxDetails["id"]); if (taxDetails.ContainsKey("name")) { tax.Name = (string)taxDetails["name"]; } if (taxDetails.ContainsKey("display_label")) { tax.DisplayName = (string)taxDetails["display_label"]; } if (taxDetails.ContainsKey("value")) { tax.Value = (double)taxDetails["value"]; } return(tax); }