Example #1
0
        public PagePropertyTemplate Create(int pageTemplateId, string propertyName, CmsPropertyType propertyType, int?tabOrder, string tabName = "", bool required = false, string description = "", string displayName = "", bool commit = true)
        {
            if (propertyName.IsNullOrEmpty())
            {
                throw new ArgumentException(Messages.PropertyTemplatePropertyNameCannotBeNull);
            }

            var pageTemplate = _unitOfWork.Context.GetDbSet <PageTemplate>()
                               .Include(x => x.PageNodes.Select(y => y.Properties.Select(z => z.PropertyTemplate)))
                               .FirstOrDefault(x => x.Id == pageTemplateId);

            if (pageTemplate == null)
            {
                throw new ArgumentException(string.Format(Messages.PageTemplateNotFound, pageTemplateId));
            }

            return(CreatePropertyTemplate(pageTemplate, propertyName, propertyType, tabOrder, tabName, required, description, displayName, commit));
        }
Example #2
0
        private PagePropertyTemplate CreatePropertyTemplate(PageTemplate pageTemplate, string propertyName, CmsPropertyType propertyType, int?tabOrder, string tabName = "", bool required = false, string description = "", string displayName = "", bool commit = true)
        {
            var propertyTemplateDbSet = _unitOfWork.Context.GetDbSet <PagePropertyTemplate>();

            var propertyTemplate = propertyTemplateDbSet.Create();

            propertyTemplate.ParentPageTemplate = pageTemplate;
            propertyTemplate.PropertyName       = propertyName;
            propertyTemplate.CmsPropertyType    = propertyType.ToString();
            propertyTemplate.DisplayName        = !displayName.IsNullOrEmpty() ? displayName : propertyName;
            propertyTemplate.TabName            = !tabName.IsNullOrEmpty() ? tabName : CmsConstants.PropertyTemplateDefaultTabName;
            propertyTemplate.Required           = required;
            propertyTemplate.Description        = description;

            if (pageTemplate.PageNodes != null && pageTemplate.PageNodes.Any())
            {
                CreateNewPropertiesForPageNodesThatUsePageTemplate(pageTemplate, propertyTemplate);
            }

            propertyTemplateDbSet.Add(propertyTemplate);

            if (commit)
            {
                _unitOfWork.Commit();
            }

            return(propertyTemplate);
        }
Example #3
0
        public PagePropertyTemplate Create(PageTemplate pageTemplate, string propertyName, CmsPropertyType propertyType, int?tabOrder, string tabName = "", bool required = false, string description = "", string displayName = "", bool commit = true)
        {
            if (propertyName.IsNullOrEmpty())
            {
                throw new ArgumentException(Messages.PropertyTemplatePropertyNameCannotBeNull);
            }

            if (pageTemplate == null)
            {
                throw new ArgumentException(Messages.PageTemplateCannotBeNull);
            }

            return(CreatePropertyTemplate(pageTemplate, propertyName, propertyType, tabOrder, tabName, required, description, displayName, commit));
        }