public RestResponse <CRMEntityMetadata> GetEntityMetadata(CRMEntityMetadata entitymetadata, 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/CRMGetEntityMetadata";

            request.AddBody(entitymetadata);

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

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

            try
            {
                entitymetadata.LogicalName = NotNull(so.Properties["EntityLogicalName"].Value);
                entitymetadata.IncludeAttributes = true;
                RestResponse<CRMEntityMetadata> response = helper.GetEntityMetadata(entitymetadata, config);

                so.Properties.InitResultTable();
                foreach (CRMAttribute ret in response.Data.Attributes)
                {
                    for (int c = 0; c < meth.ReturnProperties.Count; c += 1)
                    {
                        Property prop = so.Properties[meth.ReturnProperties[c]];
                        prop = SetGetEntityAttributeProperties(prop, ret);
                    }
                    so.Properties.BindPropertiesToResultTable();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public RestResponse<CRMEntityMetadata> GetEntityMetadata(CRMEntityMetadata entitymetadata, 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/CRMGetEntityMetadata";

            request.AddBody(entitymetadata);

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

            return response;
        }
 private Property SetEntityMetadataProperties(Property prop, CRMEntityMetadata task)
 {
     if (task != null)
     {
         switch (prop.Name.ToLower())
         {
             case "entitylogicalname":
                 prop.Value = task.LogicalName;
                 break;
             case "entitydisplayname":
                 prop.Value = task.DisplayName;
                 break;
             case "entityobjecttypecode":
                 prop.Value = task.ObjectTypeCode;
                 break;
             case "entityprimaryidattribute":
                 prop.Value = task.PrimaryIdAttribute;
                 break;
             case "entityprimarynameattribute":
                 prop.Value = task.PrimaryNameAttribute;
                 break;
             case "entityiscustomentity":
                 prop.Value = task.IsCustomEntity;
                 break;
         }
     }
     return prop;
 }