Exemplo n.º 1
0
    public IActionResult PostCreateContainer(int parentId, string name)
    {
        Attempt <OperationResult <OperationResultType, EntityContainer>?> result =
            _contentTypeService.CreateContainer(parentId, Guid.NewGuid(), name, _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id ?? -1);

        if (result.Success)
        {
            return(Ok(result.Result)); //return the id
        }

        return(ValidationProblem(result.Exception?.Message));
    }
        public IActionResult PostCreateContainer(int parentId, string name)
        {
            var result = _contentTypeService.CreateContainer(parentId, Guid.NewGuid(), name, _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.Id);

            if (result.Success)
            {
                return(Ok(result.Result)); //return the id
            }
            else
            {
                return(ValidationProblem(result.Exception.Message));
            }
        }
Exemplo n.º 3
0
        public override ContentType Create(int parentId = -1)
        {
            var parentContainer = _contentTypeService.CreateContainer(parentId, _name);

            if (parentContainer.Success)
            {
                var parentNode = _contentTypeService.GetContainers(_name, 1).FirstOrDefault();

                foreach (var component in _components)
                {
                    _contentTypeService.Save(component.Create(parentNode.Id));
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        private int GetContainerId(string containerName)
        {
            var container = _ContentTypeService.GetContainers(containerName, 1).FirstOrDefault();

            if (container != null)
            {
                return(container.Id);
            }

            var attempt = _ContentTypeService.CreateContainer(-1, containerName);

            if (attempt.Success)
            {
                return(attempt.Result.Entity.Id);
            }

            throw new InvalidOperationException($"Unable to create container: {containerName}");
        }
        private void CreateHomeDocumentType()
        {
            try
            {
                var container   = contentTypeService.GetContainers(CONTAINER, 1).FirstOrDefault();
                int containerId = 0;

                if (container == null)
                {
                    var newcontainer = contentTypeService.CreateContainer(-1, CONTAINER);

                    if (newcontainer.Success)
                    {
                        containerId = newcontainer.Result.Entity.Id;
                    }
                }
                else
                {
                    containerId = container.Id;
                }

                var contentType = contentTypeService.Get(DOCUMENT_TYPE_ALIAS);
                if (contentType == null)
                {
                    //http://refreshwebsites.co.uk/blog/umbraco-document-types-explained-in-60-seconds/
                    //https://our.umbraco.org/forum/developers/api-questions/43278-programmatically-creating-a-document-type
                    ContentType docType = (ContentType)contentType ?? new ContentType(containerId)
                    {
                        Name          = DOCUMENT_TYPE_NAME,
                        Alias         = DOCUMENT_TYPE_ALIAS,
                        AllowedAsRoot = true,
                        Description   = DOCUMENT_TYPE_DESCRIPTION,
                        Icon          = ICON,
                        SortOrder     = 0,
                        Variations    = ContentVariation.Culture
                    };

                    // Create the Template if it doesn't exist
                    if (fileService.GetTemplate(TEMPLATE_ALIAS) == null)
                    {
                        //then create the template
                        Template newTemplate = new Template(TEMPLATE_NAME, TEMPLATE_ALIAS);
                        fileService.SaveTemplate(newTemplate);
                    }

                    // Set templates for document type
                    var template = fileService.GetTemplate(TEMPLATE_ALIAS);
                    docType.AllowedTemplates = new List <ITemplate> {
                        template
                    };
                    docType.SetDefaultTemplate(template);
                    docType.AddPropertyGroup(CONTENT_TAB);
                    docType.AddPropertyGroup(TENANT_TAB);

                    // Set Document Type Properties
                    #region Tenant Home Page Content
                    PropertyType brandLogoPropType = new PropertyType(dataTypeService.GetDataType(1043), "brandLogo")
                    {
                        Name       = "Brand Logo",
                        Variations = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(brandLogoPropType, CONTENT_TAB);

                    PropertyType homeContentProType = new PropertyType(dataTypeService.GetDataType(-87), "homeContent")
                    {
                        Name       = "Content",
                        Variations = ContentVariation.Culture
                    };
                    docType.AddPropertyType(homeContentProType, CONTENT_TAB);
                    #endregion

                    #region Tenant Info Tab
                    PropertyType tenantUidPropType = new PropertyType(dataTypeService.GetDataType(-92), "tenantUid")
                    {
                        Name        = "Tenant Uid",
                        Description = "Tenant Unique Id",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(tenantUidPropType, TENANT_TAB);

                    PropertyType brandNamePropType = new PropertyType(dataTypeService.GetDataType(-92), "brandName")
                    {
                        Name       = "Brand Name",
                        Variations = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(brandNamePropType, TENANT_TAB);

                    PropertyType domainPropType = new PropertyType(dataTypeService.GetDataType(-92), "domain")
                    {
                        Name       = "Domain",
                        Variations = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(domainPropType, TENANT_TAB);

                    PropertyType subDomainPropType = new PropertyType(dataTypeService.GetDataType(-92), "subDomain")
                    {
                        Name       = "Sub Domain",
                        Variations = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(subDomainPropType, TENANT_TAB);

                    PropertyType appIdPropType = new PropertyType(dataTypeService.GetDataType(-92), "appId")
                    {
                        Name       = "App Id",
                        Variations = ContentVariation.Nothing
                    };

                    docType.AddPropertyType(appIdPropType, TENANT_TAB);

                    PropertyType apiKeyPropType = new PropertyType(dataTypeService.GetDataType(-92), "apiKey")
                    {
                        Name       = "Api Key",
                        Variations = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(apiKeyPropType, TENANT_TAB);

                    PropertyType defaultLanguagePropType = new PropertyType(dataTypeService.GetDataType(-92), "defaultLanguage")
                    {
                        Name        = "Default Language",
                        Description = "System Default Language",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(defaultLanguagePropType, TENANT_TAB);

                    PropertyType languagestPropType = new PropertyType(dataTypeService.GetDataType(-92), "languages")
                    {
                        Name       = "Alternate Languages",
                        Variations = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(languagestPropType, TENANT_TAB);

                    PropertyType tenantStatusPropType = new PropertyType(dataTypeService.GetDataType(-92), "tenantStatus")
                    {
                        Name        = "Tenant Status",
                        Description = "Total Code Tenant Status",
                        Variations  = ContentVariation.Nothing
                    };
                    docType.AddPropertyType(tenantStatusPropType, TENANT_TAB);
                    #endregion

                    contentTypeService.Save(docType);
                    ConnectorContext.AuditService.Add(AuditType.New, -1, docType.Id, "Document Type", $"Document Type '{DOCUMENT_TYPE_NAME}' has been created");

                    ContentHelper.CopyPhysicalAssets(new EmbeddedResources());
                }
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(HomeDocumentType), ex.Message);
                logger.Error(typeof(HomeDocumentType), ex.StackTrace);
            }
        }