Beispiel #1
0
        public bool DeleteEntity(IOrganizationService service, XRMSpeedyEntity entity)
        {
            try
            {
                DeleteEntityRequest delete = new DeleteEntityRequest
                {
                    LogicalName = entity.EntityMetadata.SchemaName
                };

                service.Execute(delete);
                return(true);
            }
            catch (FaultException <OrganizationServiceFault> )
            {
                throw;
            }
        }
Beispiel #2
0
        private bool CreateAttributes(IOrganizationService service, XRMSpeedyEntity entity, int languageCode)
        {
            try
            {
                foreach (XRMSpeedyField field in entity.Fields.Where(f => f.Import == true))
                {
                    CreateAttributeRequest request = new CreateAttributeRequest
                    {
                        EntityName = entity.EntityMetadata.SchemaName,
                        Attribute  = field.AttributeMetadata
                    };

                    CreateAttributeResponse response = (CreateAttributeResponse)service.Execute(request);
                }
                return(true);
            }
            catch (FaultException <OrganizationServiceFault> )
            {
                throw;
            }
        }
Beispiel #3
0
        public bool CreateEntity(IOrganizationService service, XRMSpeedyEntity entity, int languageCode)
        {
            try
            {
                CreateEntityRequest createRequest = new CreateEntityRequest
                {
                    Entity = new EntityMetadata
                    {
                        SchemaName            = entity.EntityMetadata.SchemaName,
                        DisplayName           = entity.EntityMetadata.DisplayName,
                        DisplayCollectionName = entity.EntityMetadata.DisplayCollectionName,
                        Description           = entity.EntityMetadata.Description,
                        OwnershipType         = entity.EntityMetadata.OwnershipType,
                        IsActivity            = false
                    },

                    // Define the primary attribute for the entity
                    PrimaryAttribute = new StringAttributeMetadata
                    {
                        SchemaName = entity.ShortPrimaryAttributeName
                            ? entity.EntityMetadata.SchemaName.Split('_')[0] + "_" + "name"
                            : entity.EntityMetadata.SchemaName + "name",
                        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired),
                        MaxLength     = entity.PrimaryAttributeSize,
                        Format        = StringFormat.Text,
                        DisplayName   = new Label("Name", languageCode),
                        Description   = new Label("The primary attribute for the entity.", languageCode)
                    }
                };

                CreateEntityResponse response = (CreateEntityResponse)service.Execute(createRequest);

                return(CreateAttributes(service, entity, languageCode));
            }
            catch (FaultException <OrganizationServiceFault> )
            {
                throw;
            }
        }