public RestResponse <CRMRetrieveMultiple> RetrieveMultiple(CRMRetrieveMultiple retrieveMultiple, K2CRMConfig config)
        {
            var client = new RestClient(config.RESTUrl);

            var request = new RestRequest();

            request.Method = Method.POST;
            if (config.CredentialCache != null)
            {
                request.Credentials = config.CredentialCache;
            }
            if (config.Credentials != null)
            {
                request.Credentials = config.Credentials;
            }


            request.RequestFormat = RestSharp.DataFormat.Json;
            request.Resource      = "K2CRM/CRMRetrieveMultiple";

            request.AddBody(retrieveMultiple);

            RestResponse <CRMRetrieveMultiple> response = client.Execute <CRMRetrieveMultiple>(request);

            return(response);
        }
        public RestResponse<CRMRetrieveMultiple> RetrieveMultiple(CRMRetrieveMultiple retrieveMultiple, K2CRMConfig config)
        {
            var client = new RestClient(config.RESTUrl);

            var request = new RestRequest();
            request.Method = Method.POST;
            if (config.CredentialCache != null)
            {
                request.Credentials = config.CredentialCache;
            }
            if (config.Credentials != null)
            {
                request.Credentials = config.Credentials;
            }


            request.RequestFormat = RestSharp.DataFormat.Json;
            request.Resource = "K2CRM/CRMRetrieveMultiple";

            request.AddBody(retrieveMultiple);

            RestResponse<CRMRetrieveMultiple> response = client.Execute<CRMRetrieveMultiple>(request);

            return response;
        }
        private void RetrieveMultiple(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            //K2CRMHelper helper = new K2CRMHelper();
            WizardFunctions helper = new WizardFunctions();
            CRMRetrieveMultiple multiple = new CRMRetrieveMultiple();
            multiple.Config = crmconfig;

            try
            {
                multiple.LinkFromEntityName = NotNull(so.Properties["LinkFromEntityName"].Value);
                multiple.LinkFromAttributeName = NotNull(so.Properties["LinkFromAttributeName"].Value);
                multiple.LinkToEntityName = NotNull(so.Properties["LinkToEntityName"].Value);
                multiple.LinkToAttributeName = NotNull(so.Properties["LinkToAttributeName"].Value);
                multiple.ConditionAttributeName = NotNull(so.Properties["ConditionAttributeName"].Value);
                multiple.ConditionOperator = NotNull(so.Properties["ConditionOperator"].Value);
                multiple.ConditionValue = NotNull(so.Properties["ConditionValue"].Value);
                multiple.ReturnAttributes = NotNull(so.Properties["ReturnAttributes"].Value);

                RestResponse<CRMRetrieveMultiple> response = helper.RetrieveMultiple(multiple, config);

                so.Properties.InitResultTable();

                foreach (CRMRetrieveMultipleReturn ret in response.Data.Results)
                { 
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetRetrieveMultipleProperties(prop, response);
                        prop = SetRetrieveMultipleReturnProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
                

            }
            catch (Exception ex)
            {
                throw;
            }
        }