private void BulkActionTasks(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            WizardFunctions helper = new WizardFunctions();

            CRMBulkActionTask fetch = new CRMBulkActionTask();

            fetch.Config = crmconfig;

            try
            {
                fetch.FetchXML   = NotNull(so.Properties["FetchXML"].Value);
                fetch.FromState  = int.Parse(NotNull(so.Properties["FromState"].Value));
                fetch.FromStatus = int.Parse(NotNull(so.Properties["FromStatus"].Value));
                fetch.ToState    = int.Parse(NotNull(so.Properties["ToState"].Value));
                fetch.ToStatus   = int.Parse(NotNull(so.Properties["ToStatus"].Value));

                RestResponse <CRMBulkActionTask> response = helper.BulkActionTasks(fetch, config);

                so.Properties.InitResultTable();

                if (response.Data != null && response.Data.Entities != null)
                {
                    foreach (CRMState state in response.Data.Entities)
                    {
                        for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                        {
                            Property prop = so.Properties[meth.ReturnProperties[c]];
                            prop = SetGetEntitiesProperties(prop, state);
                            prop = SetBulkActionTasksRESTProperties(prop, response);
                        }
                        so.Properties.BindPropertiesToResultTable();
                    }
                }
                else
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetBulkActionTasksRESTProperties(prop, response);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public RestResponse<CRMBulkActionTask> BulkActionTasks(CRMBulkActionTask crmBulk, K2CRMConfig config)
        {
            var client = new RestClient(config.RESTUrl);

            var request = new RestRequest();
            request.Method = Method.POST;
            request.Credentials = config.CredentialCache;
            request.RequestFormat = RestSharp.DataFormat.Json;
            request.Resource = "K2CRM/CRMBulkActionTasks";

            request.AddBody(crmBulk);

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

            return response;
        }
        public RestResponse <CRMBulkActionTask> BulkActionTasks(CRMBulkActionTask crmBulk, K2CRMConfig config)
        {
            var client = new RestClient(config.RESTUrl);

            var request = new RestRequest();

            request.Method        = Method.POST;
            request.Credentials   = config.CredentialCache;
            request.RequestFormat = RestSharp.DataFormat.Json;
            request.Resource      = "K2CRM/CRMBulkActionTasks";

            request.AddBody(crmBulk);

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

            return(response);
        }
        private void BulkActionTasksSetCriteria(ref ServiceObject so)
        {
            SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0];
            WizardFunctions helper = new WizardFunctions();

            CRMBulkActionTask fetch = new CRMBulkActionTask();

            fetch.Config = crmconfig;

            try
            {
                string fetchstring = string.Empty;
                if (!string.IsNullOrEmpty(NotNull(so.Properties["K2ActivityName"])))
                {
                    fetchstring = Resources.K2CRMTaskCleanUpFinishRule.Replace("[entityid]", NotNull(so.Properties["RegardingId"].Value)).Replace("[entityname]", NotNull(so.Properties["Regarding"].Value));
                    fetchstring = fetchstring.Replace("[processname]", NotNull(so.Properties["K2ProcessName"].Value));
                    fetchstring = fetchstring.Replace("[statecode]", NotNull(so.Properties["FromState"].Value));
                    fetchstring = fetchstring.Replace("[processinstanceid]", NotNull(so.Properties["K2ProcessInstanceId"].Value));
                }
                else
                {
                    fetchstring = Resources.K2CRMTaskCleanUpState0FetchXML.Replace("[entityid]", NotNull(so.Properties["RegardingId"].Value)).Replace("[entityname]", NotNull(so.Properties["Regarding"].Value));
                    fetchstring = fetchstring.Replace("[activityname]", NotNull(so.Properties["K2ActivityName"].Value));
                    fetchstring = fetchstring.Replace("[processname]", NotNull(so.Properties["K2ProcessName"].Value));
                    fetchstring = fetchstring.Replace("[statecode]", NotNull(so.Properties["FromState"].Value));
                    fetchstring = fetchstring.Replace("[processinstanceid]", NotNull(so.Properties["K2ProcessInstanceId"].Value));
                }

                fetch.FetchXML   = fetchstring;
                fetch.FromState  = int.Parse(NotNull(so.Properties["FromState"].Value));
                fetch.FromStatus = int.Parse(NotNull(so.Properties["FromStatus"].Value));
                fetch.ToState    = int.Parse(NotNull(so.Properties["ToState"].Value));
                fetch.ToStatus   = int.Parse(NotNull(so.Properties["ToStatus"].Value));

                RestResponse <CRMBulkActionTask> response = helper.BulkActionTasks(fetch, config);

                so.Properties.InitResultTable();

                if (response.Data != null && response.Data.Entities != null)
                {
                    foreach (CRMState state in response.Data.Entities)
                    {
                        for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                        {
                            Property prop = so.Properties[meth.ReturnProperties[c]];
                            prop = SetGetEntitiesProperties(prop, state);
                            prop = SetBulkActionTasksRESTProperties(prop, response);
                        }
                        so.Properties.BindPropertiesToResultTable();
                    }
                }
                else
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetBulkActionTasksRESTProperties(prop, response);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }