Beispiel #1
0
        public void ContentTemplate_CreationDate()
        {
            if (_fileGlobalTemplate1 == null)
            {
                CreatePlayGround();
            }

            Thread.Sleep(1000);
            var t0 = DateTime.UtcNow;

            Thread.Sleep(10);

            var y = ContentTemplate.CreateFromTemplate(TestRoot, _fileGlobalTemplate1, null);

            y.Save();

            y = Node.LoadNode(y.Id);
            Assert.IsTrue(t0 < y.CreationDate);
            Assert.IsTrue(t0 < y.ModificationDate);
            Assert.IsTrue(t0 < y.VersionCreationDate);
            Assert.IsTrue(t0 < y.VersionModificationDate);
        }
        private Content CreateContent(JObject model, ODataRequest odataRequest)
        {
            var contentTypeName = GetPropertyValue <string>("__ContentType", model);
            var templateName    = GetPropertyValue <string>("__ContentTemplate", model);

            var name = GetPropertyValue <string>("Name", model);

            if (string.IsNullOrEmpty(name))
            {
                var displayName = GetPropertyValue <string>("DisplayName", model);
                name = ContentNamingProvider.GetNameFromDisplayName(displayName);
            }
            else
            {
                // do not allow saving a content with unencoded name
                name = ContentNamingProvider.GetNameFromDisplayName(name);
            }

            var parent = Node.Load <GenericContent>(odataRequest.RepositoryPath);

            if (string.IsNullOrEmpty(contentTypeName))
            {
                var allowedChildTypeNames = parent.GetAllowedChildTypeNames();

                if (allowedChildTypeNames is AllContentTypeNames)
                {
                    contentTypeName = typeof(ContentRepository.File).Name;
                }
                else
                {
                    var allowedContentTypeNames = parent.GetAllowedChildTypeNames().ToArray();
                    contentTypeName = allowedContentTypeNames.FirstOrDefault();
                    if (string.IsNullOrEmpty(contentTypeName))
                    {
                        contentTypeName = typeof(ContentRepository.File).Name;
                    }
                }
            }

            Content content;
            Node    template = null;

            if (templateName != null)
            {
                template = ContentTemplate.GetNamedTemplate(contentTypeName, templateName);
            }

            if (template == null)
            {
                content = Content.CreateNew(contentTypeName, parent, name);
            }
            else
            {
                var templated = ContentTemplate.CreateFromTemplate(parent, template, name);
                content = Content.Create(templated);
            }


            UpdateFields(content, model);

            if (odataRequest.MultistepSave)
            {
                content.Save(SavingMode.StartMultistepSave);
            }
            else
            {
                content.Save();
            }

            return(content);
        }