Exemple #1
0
        private void AddToPanelPickerAllowedEditors()
        {
            var panelPickerDataType = _dataTypeService.GetDataTypeDefinitionByName(PanelsInstallationConstants.DataTypeNames.PanelPicker);
            var preValuesDictionary = _dataTypeService.GetPreValuesCollectionByDataTypeId(panelPickerDataType.Id).PreValuesAsDictionary;

            AddAllowedEditor(preValuesDictionary, TableEditor);
            _dataTypeService.SaveDataTypeAndPreValues(panelPickerDataType, preValuesDictionary);
        }
Exemple #2
0
        private void AddToDefaultGridAllowedEditors()
        {
            var defaultGridDataType = _dataTypeService.GetDataTypeDefinitionByName(CoreInstallationConstants.DataTypeNames.ContentGrid);
            var preValuesDictionary = _dataTypeService.GetPreValuesCollectionByDataTypeId(defaultGridDataType.Id).PreValuesAsDictionary;

            GridInstallationHelper.AddAllowedEditorForOneColumnRow(preValuesDictionary, UserListAlias);

            _dataTypeService.SaveDataTypeAndPreValues(defaultGridDataType, preValuesDictionary);
        }
        private void Synchronize(IDataTypeDefinition[] dataTypes, DataType model)
        {
            var dataType = _dataTypeFinder.Find(model, dataTypes).SingleOrDefault();

            if (dataType == null)
            {
                // Create new data type.
                dataType = CreateDataType(model);

                _dataTypeService.SaveDataTypeAndPreValues(dataType, GetPreValues(model));
            }
            else
            {
                // Update the data type and its pre-values.
                _dataTypeService.Save(UpdateDataTypeDefinition(dataType, model));

                var existingPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).FormatAsDictionary();

                var preValuesToSave = existingPreValues.Any()
                    ? GetUpdatedPreValues(existingPreValues, model.PreValues)
                    : GetPreValues(model);

                _dataTypeService.SavePreValues(dataType.Id, preValuesToSave);
            }

            // We get the data type once more to refresh it after saving it.
            dataType = _dataTypeService.GetDataTypeDefinitionByName(dataType.Name);

            // Set/update tracking.
            SetDataTypeId(model, dataType);
        }
Exemple #4
0
        /// <summary>
        /// Convert ContentPickerAlias data types with the given name
        ///
        /// Converts the content from ids to UDIs
        /// Swaps the data type alias itself over
        /// </summary>
        /// <param name="name"></param>
        public void Convert(string name)
        {
            var oldDataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(name);

            oldDataTypeDefinition.Name = oldDataTypeDefinition.Name + " (Obsolete)";
            _dataTypeService.Save(oldDataTypeDefinition);

            var oldPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(oldDataTypeDefinition.Id);

            var newDataTypeDefinition = new DataTypeDefinition(_newDataTypeAlias);

            newDataTypeDefinition.Name = name;
            _dataTypeService.SaveDataTypeAndPreValues(newDataTypeDefinition, _preValueConversion == null ? new Dictionary <string, PreValue>() : _preValueConversion(oldPreValues.PreValuesAsDictionary));

            var allContentTypes       = _contentTypeService.GetAllContentTypes();
            var contentTypesToConvert = allContentTypes
                                        .Where(c =>
                                               c.PropertyTypes.Any(a => a.DataTypeDefinitionId == oldDataTypeDefinition.Id) ||
                                               c.CompositionPropertyTypes.Any(a => a.DataTypeDefinitionId == oldDataTypeDefinition.Id))
                                        .ToArray();

            AddReplacementDataType(contentTypesToConvert, oldDataTypeDefinition, newDataTypeDefinition);
            ConvertContent(contentTypesToConvert, oldDataTypeDefinition);
            DeleteOldDataType(oldDataTypeDefinition);
        }
Exemple #5
0
        public void Convert(string name)
        {
            var nestedContentDataType = _dataTypeService.GetDataTypeDefinitionByName(name);
            var preValues             = _dataTypeService.GetPreValuesCollectionByDataTypeId(nestedContentDataType.Id).FormatAsDictionary();

            nestedContentDataType.PropertyEditorAlias = "Umbraco.NestedContent";

            _dataTypeService.SaveDataTypeAndPreValues(nestedContentDataType, preValues);
        }
Exemple #6
0
        /// <summary>
        /// Updates the prevalues for the property editor
        /// </summary>
        /// <param name="prevalue">The new value</param>
        /// <param name="alias">The prevalue to update</param>
        public void UpdatePrevalueForEditor(string prevalue, string alias)
        {
            IDataTypeDefinition            datatype  = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(Alias).First();
            IDictionary <string, PreValue> prevalues = _dataTypeService.GetPreValuesCollectionByDataTypeId(datatype.Id).PreValuesAsDictionary;

            prevalues[alias] = new PreValue(prevalue);

            _dataTypeService.SaveDataTypeAndPreValues(datatype, prevalues);
        }
Exemple #7
0
        private void UpdateDatatypePreValues(IDataTypeService dataTypeService, string dataTypeName,
                                             string assemblyFullNamePreValue, string enumFullNamePreValue)
        {
            var dataType = dataTypeService.GetDataTypeDefinitionByName(dataTypeName);

            if (dataType != null)
            {
                var preValues  = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id);
                var dictionary = preValues.FormatAsDictionary();
                dictionary[FolderConstants.PreValueAssemblyAlias].Value = assemblyFullNamePreValue;
                dictionary[FolderConstants.PreValueEnumAlias].Value     = enumFullNamePreValue;

                dataTypeService.SaveDataTypeAndPreValues(dataType, dictionary);
            }
        }
        private void PersistDataTypeAndPreValues(DataTypeRegistration dataTypeRegistration, IDataTypeDefinition dataTypeDefinition, IDictionary <string, PreValue> preValues)
        {
            CodeFirstManager.Current.Log("Saving data type " + dataTypeRegistration.DataTypeInstanceName, this);
            if (CodeFirstManager.Current.Features.InitialisationMode == InitialisationMode.Ensure)
            {
                throw new CodeFirstPassiveInitialisationException("The data types or prevalues defined in the database do not match the types passed in to initialise. In InitialisationMode.Ensure the types must match or the site will be prevented from starting.");
            }
            else if (CodeFirstManager.Current.Features.InitialisationMode == InitialisationMode.Sync)
            {
                UmbracoContext.EnsureContext(new HttpContextWrapper(new HttpContext(new HttpRequest("", "http://tempuri.org", ""), new HttpResponse(new StringWriter()))), ApplicationContext.Current, true);

                _service.SaveDataTypeAndPreValues(dataTypeDefinition, preValues);
                //reset the collection if we've modified a type
                _allDataTypeDefinitions = new Lazy <IEnumerable <IDataTypeDefinition> >(() =>
                {
                    return(_service.GetAllDataTypeDefinitions());
                });
            }
            else if (CodeFirstManager.Current.Features.InitialisationMode != InitialisationMode.Passive)
            {
                throw new CodeFirstException("Unknown initialisation mode");
            }
        }
Exemple #9
0
        private void RemoveFromPreValues(IEnumerable <string> editorsToRemove)
        {
            const string itemsKey = "items";

            var defaultGridDataType = _dataTypeService.GetDataTypeDefinitionByName(CoreInstallationConstants.DataTypeNames.DefaultGrid);
            var preValues           = _dataTypeService.GetPreValuesCollectionByDataTypeId(defaultGridDataType.Id);
            var preValuesDictionary = preValues.FormatAsDictionary();
            var items            = preValuesDictionary[itemsKey].Value.Pipe(Json.Decode);
            var availableEditors = items.layouts[0].areas[0].allowed;

            var availableEditorsList = new List <string>();

            foreach (var editor in availableEditors)
            {
                availableEditorsList.Add((string)editor);
            }

            var actualEditors = availableEditorsList.Except(editorsToRemove);

            items.layouts[0].areas[0].allowed   = JArray.FromObject(actualEditors).ToDynamic();
            preValuesDictionary[itemsKey].Value = JsonConvert.SerializeObject(items);

            _dataTypeService.SaveDataTypeAndPreValues(defaultGridDataType, preValuesDictionary);
        }
        public bool Execute(string packageName, XmlNode xmlData)
        {
            IMediaService       mediaService       = ApplicationContext.Current.Services.MediaService;
            IContentService     contentService     = UmbracoContext.Current.Application.Services.ContentService;
            IContentTypeService contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
            IFileService        fileService        = ApplicationContext.Current.Services.FileService;
            //ApplicationContext.Current.Services.DataTypeService.
            IDataTypeService dataTypeService = UmbracoContext.Current.Application.Services.DataTypeService;

            #region Create media
            List <int>    productImageIds = new List <int>();
            List <IMedia> productImages   = new List <IMedia>();
            try {
                //Create image files
                const string productImagesFolderName = "Product images";
                string[]     mediaInstallImages      = Directory.GetFiles(HostingEnvironment.MapPath("~/Assets/InstallMedia"));
                IMedia       productImagesFolder     = mediaService.GetByLevel(1).FirstOrDefault(m => m.Name == productImagesFolderName);
                if (productImagesFolder == null)
                {
                    productImagesFolder = mediaService.CreateMedia(productImagesFolderName, -1, "Folder");
                    mediaService.Save(productImagesFolder);
                }

                if (!productImagesFolder.Children().Any())
                {
                    foreach (string mediaInstallImage in mediaInstallImages)
                    {
                        string fileName     = Path.GetFileName(mediaInstallImage);
                        IMedia productImage = mediaService.CreateMedia(fileName, productImagesFolder.Id, "Image");
                        byte[] buffer       = File.ReadAllBytes(Path.GetFullPath(mediaInstallImage));
                        using (MemoryStream strm = new MemoryStream(buffer)) {
                            productImage.SetValue("umbracoFile", fileName, strm);
                            mediaService.Save(productImage);
                            productImages.Add(productImage);
                            productImageIds.Add(productImage.Id);
                        }
                    }
                }
                else
                {
                    productImageIds = productImagesFolder.Children().Select(c => c.Id).ToList();
                }

                Directory.Delete(HostingEnvironment.MapPath("~/Assets/InstallMedia"), true);
            } catch (Exception ex) {
                LogHelper.Error <TeaCommerceStarterKitInstall>("Create media failed", ex);
            }
            #endregion

            #region Set up Tea Commerce
            Store store = null;
            try {
                //Get store or create it
                IReadOnlyList <Store> stores = StoreService.Instance.GetAll().ToList();
                store = stores.FirstOrDefault();
                if (store == null)
                {
                    store = new Store("Starter Kit Store");
                }

                store.ProductSettings.ProductVariantPropertyAlias = "variants";
                store.Save();

                foreach (PaymentMethod paymentMethod in PaymentMethodService.Instance.GetAll(store.Id).Where(p => p.Alias == "invoicing"))
                {
                    PaymentMethodSetting setting = paymentMethod.Settings.FirstOrDefault(s => s.Key == "acceptUrl");
                    if (setting != null)
                    {
                        setting.Value = "/cart-content/confirmation/";
                    }
                    paymentMethod.Save();
                }
            } catch (Exception ex) {
                LogHelper.Error <TeaCommerceStarterKitInstall>("Setting up Tea Commerce failed", ex);
            }
            #endregion

            #region Create Templates
            List <ITemplate> templates = new List <ITemplate>();
            try {
                string[] templateFiles = Directory.GetFiles(HostingEnvironment.MapPath("~/views"));
                foreach (string templateFile in templateFiles)
                {
                    string fileName    = Path.GetFileNameWithoutExtension(templateFile);
                    string fileContent = File.ReadAllText(templateFile);
                    templates.Add(fileService.CreateTemplateWithIdentity(fileName, fileContent));
                }
            } catch (Exception ex) {
                LogHelper.Error <TeaCommerceStarterKitInstall>("Create templates failed", ex);
            }
            #endregion

            #region Set up content types

            IEnumerable <IDataTypeDefinition> allDataTypeDefinitions = dataTypeService.GetAllDataTypeDefinitions();
            try {
                IDataTypeDefinition variantEditorDataTypeDefinition = allDataTypeDefinitions.FirstOrDefault(d => d.Name.ToLowerInvariant().Contains("variant editor"));
                variantEditorDataTypeDefinition.DatabaseType = DataTypeDatabaseType.Ntext;

                var preValDictionary = new Dictionary <string, object> {
                    { "xpathOrNode", "{\"showXPath\": true,\"query\": \"$current/ancestor-or-self::frontpage/attributes\"}" },
                    { "variantDocumentType", "variant" },
                    { "extraListInformation", "sku,priceJMD" },
                    { "hideLabel", "1" },
                };
                var currVal = dataTypeService.GetPreValuesCollectionByDataTypeId(variantEditorDataTypeDefinition.Id);

                //we need to allow for the property editor to deserialize the prevalues
                PropertyEditor pe           = PropertyEditorResolver.Current.PropertyEditors.SingleOrDefault(x => x.Alias == "TeaCommerce.VariantEditor");
                var            formattedVal = pe.PreValueEditor.ConvertEditorToDb(preValDictionary, currVal);
                dataTypeService.SaveDataTypeAndPreValues(variantEditorDataTypeDefinition, formattedVal);
                //dataTypeService.Save( variantEditorDataTypeDefinition );
                variantEditorDataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(variantEditorDataTypeDefinition.Id);
            } catch (Exception ex) {
                LogHelper.Error <TeaCommerceStarterKitInstall>("Set up content types failed", ex);
            }
            #endregion

            #region Create Document types
            ContentType attributeContentType      = null,
                        attributeGroupContentType = null,
                        attributesContentType     = null,
                        cartStepContentType       = null,
                        cartContentType           = null,
                        variantContentType        = null,
                        productContentType        = null,
                        productListContentType    = null,
                        frontpageContentType      = null;
            try {
                attributeContentType       = new ContentType(-1);
                attributeContentType.Alias = "attribute";
                attributeContentType.Name  = "Attribute";
                attributeContentType.Icon  = "icon-t-shirt";
                contentTypeService.Save(attributeContentType);

                attributeGroupContentType       = new ContentType(-1);
                attributeGroupContentType.Alias = "attributeGroup";
                attributeGroupContentType.Name  = "Attribute group";
                attributeGroupContentType.Icon  = "icon-t-shirt color-orange";
                attributeGroupContentType.AllowedContentTypes = new List <ContentTypeSort>()
                {
                    new ContentTypeSort(attributeContentType.Id, 0)
                };
                contentTypeService.Save(attributeGroupContentType);

                attributesContentType       = new ContentType(-1);
                attributesContentType.Alias = "attributes";
                attributesContentType.Name  = "Attributes";
                attributesContentType.Icon  = "icon-t-shirt";
                attributesContentType.AllowedContentTypes = new List <ContentTypeSort>()
                {
                    new ContentTypeSort(attributeGroupContentType.Id, 0)
                };
                contentTypeService.Save(attributesContentType);

                cartStepContentType                  = new ContentType(-1);
                cartStepContentType.Alias            = "cartStep";
                cartStepContentType.Name             = "Cart step";
                cartStepContentType.Icon             = "icon-shopping-basket-alt-2 color-orange";
                cartStepContentType.AllowedTemplates = templates.Where(t => t.Alias.ToLowerInvariant().Contains("cartstep") && !t.Alias.ToLowerInvariant().Contains("master"));
                contentTypeService.Save(cartStepContentType);

                cartContentType       = new ContentType(-1);
                cartContentType.Alias = "cart";
                cartContentType.Name  = "Cart";
                cartContentType.Icon  = "icon-shopping-basket-alt-2";
                cartContentType.AllowedContentTypes = new List <ContentTypeSort>()
                {
                    new ContentTypeSort(cartStepContentType.Id, 0)
                };
                cartContentType.AllowedTemplates = templates.Where(t => t.Alias.ToLowerInvariant().Contains("cartstep1"));
                contentTypeService.Save(cartContentType);

                variantContentType = CreateVariantContentType(allDataTypeDefinitions, contentTypeService);
                productContentType = CreateProductContentType(allDataTypeDefinitions, contentTypeService, templates);

                productListContentType       = new ContentType(-1);
                productListContentType.Alias = "productList";
                productListContentType.Name  = "Product list";
                productListContentType.Icon  = "icon-tags";
                productListContentType.AllowedContentTypes = new List <ContentTypeSort>()
                {
                    new ContentTypeSort(productContentType.Id, 0)
                };
                productListContentType.AllowedTemplates = templates.Where(t => t.Alias.ToLowerInvariant().Contains("productlist"));
                contentTypeService.Save(productListContentType);

                frontpageContentType = CreateFrontpageContentType(allDataTypeDefinitions, contentTypeService, templates);
            } catch (Exception ex) {
                LogHelper.Error <TeaCommerceStarterKitInstall>("Create templates failed", ex);
            }
            #endregion

            #region Create content
            try {
                Content frontPageContent = new Content("Home", -1, frontpageContentType);
                frontPageContent.Template = frontpageContentType.AllowedTemplates.First();
                frontPageContent.SetValue("slider", string.Join(",", productImages.Select(p => "umb://media/" + p.Key.ToString().Replace("-", ""))));
                frontPageContent.SetValue("store", store.Id);
                contentService.SaveAndPublishWithStatus(frontPageContent, raiseEvents: false);

                #region Create Cart
                Content cartContent = new Content("Cart content", frontPageContent.Id, cartContentType);
                cartContent.Template = cartContentType.AllowedTemplates.First();
                contentService.SaveAndPublishWithStatus(cartContent, raiseEvents: false);
                Content informationContent = new Content("Information", cartContent.Id, cartStepContentType);
                informationContent.Template = templates.First(t => t.Alias.ToLowerInvariant() == "cartstep2");
                contentService.SaveAndPublishWithStatus(informationContent, raiseEvents: false);
                Content shippingPaymentContent = new Content("Shipping/Payment", cartContent.Id, cartStepContentType);
                shippingPaymentContent.Template = templates.First(t => t.Alias.ToLowerInvariant() == "cartstep3");
                contentService.SaveAndPublishWithStatus(shippingPaymentContent, raiseEvents: false);
                Content acceptContent = new Content("Accept", cartContent.Id, cartStepContentType);
                acceptContent.Template = templates.First(t => t.Alias.ToLowerInvariant() == "cartstep4");
                contentService.SaveAndPublishWithStatus(acceptContent, raiseEvents: false);
                Content paymentContent = new Content("Payment", cartContent.Id, cartStepContentType);
                contentService.SaveAndPublishWithStatus(paymentContent);
                Content confirmationContent = new Content("Confirmation", cartContent.Id, cartStepContentType);
                confirmationContent.Template = templates.First(t => t.Alias.ToLowerInvariant() == "cartstep6");
                contentService.SaveAndPublishWithStatus(confirmationContent, raiseEvents: false);
                #endregion

                #region Create Attributes
                Content variantAttributesContent = new Content("Variant attributes", frontPageContent.Id, attributesContentType);
                contentService.SaveAndPublishWithStatus(variantAttributesContent, raiseEvents: false);
                Content colorContent = new Content("Color", variantAttributesContent.Id, attributeGroupContentType);
                contentService.SaveAndPublishWithStatus(colorContent, raiseEvents: false);
                Content sizeContent = new Content("Size", variantAttributesContent.Id, attributeGroupContentType);
                contentService.SaveAndPublishWithStatus(sizeContent, raiseEvents: false);
                Content blackContent = new Content("Black", colorContent.Id, attributeContentType);
                contentService.SaveAndPublishWithStatus(blackContent, raiseEvents: false);
                Content whiteContent = new Content("White", colorContent.Id, attributeContentType);
                contentService.SaveAndPublishWithStatus(whiteContent, raiseEvents: false);
                Content blueContent = new Content("Blue", colorContent.Id, attributeContentType);
                contentService.SaveAndPublishWithStatus(blueContent, raiseEvents: false);
                Content largeContent = new Content("Large", sizeContent.Id, attributeContentType);
                contentService.SaveAndPublishWithStatus(largeContent, raiseEvents: false);
                Content mediumContent = new Content("Medium", sizeContent.Id, attributeContentType);
                contentService.SaveAndPublishWithStatus(mediumContent, raiseEvents: false);
                Content smallContent = new Content("Small", sizeContent.Id, attributeContentType);
                contentService.SaveAndPublishWithStatus(smallContent, raiseEvents: false);
                #endregion

                #region Create Products
                Content expensiveYachtsContent = new Content("Expensive Yachts", frontPageContent.Id, productListContentType);
                expensiveYachtsContent.Template = productListContentType.AllowedTemplates.First();
                contentService.SaveAndPublishWithStatus(expensiveYachtsContent, raiseEvents: false);
                Content veryAxpensiveYachtsContent = new Content("Very expensive Yachts", frontPageContent.Id, productListContentType);
                veryAxpensiveYachtsContent.Template = productListContentType.AllowedTemplates.First();
                contentService.SaveAndPublishWithStatus(veryAxpensiveYachtsContent, raiseEvents: false);
                Content summerYachtContent = new Content("Summer Yacht", expensiveYachtsContent, productContentType);
                summerYachtContent.Template = productContentType.AllowedTemplates.First();
                summerYachtContent.SetValue("image", "umb://media/" + productImages[0].Key.ToString().Replace("-", ""));
                summerYachtContent.SetValue("productName", "Summer Yacht");
                summerYachtContent.SetValue("sku", "p0001");
                summerYachtContent.SetValue("priceJMD", "500");
                summerYachtContent.SetValue("description", "<p>This is the product description.</p>");
                summerYachtContent.SetValue("variants", "{\"variants\": [],\"variantGroupsOpen\":{}}");
                contentService.SaveAndPublishWithStatus(summerYachtContent, raiseEvents: false);
                Content yachtWithSailsContent = new Content("Yacht with sails", expensiveYachtsContent, productContentType);
                yachtWithSailsContent.Template = productContentType.AllowedTemplates.First();
                yachtWithSailsContent.SetValue("image", "umb://media/" + productImages[1].Key.ToString().Replace("-", ""));
                yachtWithSailsContent.SetValue("productName", "Yacht with sails");
                yachtWithSailsContent.SetValue("sku", "p0002");
                yachtWithSailsContent.SetValue("priceJMD", "1000");
                yachtWithSailsContent.SetValue("description", "<p>This is the product description.</p>");
                yachtWithSailsContent.SetValue("variants", "{\"variants\": [],\"variantGroupsOpen\":{}}");
                contentService.SaveAndPublishWithStatus(yachtWithSailsContent, raiseEvents: false);
                Content motorDrivenYachtContent = new Content("Motor driven Yacht", veryAxpensiveYachtsContent, productContentType);
                motorDrivenYachtContent.Template = productContentType.AllowedTemplates.First();
                motorDrivenYachtContent.SetValue("image", "umb://media/" + productImages[2].Key.ToString().Replace("-", ""));
                motorDrivenYachtContent.SetValue("productName", "Motor driven Yacht");
                motorDrivenYachtContent.SetValue("sku", "p0003");
                motorDrivenYachtContent.SetValue("priceJMD", "1500");
                motorDrivenYachtContent.SetValue("description", "<p>This is the product description.</p>");
                motorDrivenYachtContent.SetValue("variants", "{\"variants\": [],\"variantGroupsOpen\":{}}");
                contentService.SaveAndPublishWithStatus(motorDrivenYachtContent, raiseEvents: false);
                Content oneMastedYachtContent = new Content("One masted yacht", veryAxpensiveYachtsContent, productContentType);
                oneMastedYachtContent.Template = productContentType.AllowedTemplates.First();
                oneMastedYachtContent.SetValue("image", "umb://media/" + productImages[3].Key.ToString().Replace("-", ""));
                oneMastedYachtContent.SetValue("productName", "One masted yacht");
                oneMastedYachtContent.SetValue("sku", "p0004");
                oneMastedYachtContent.SetValue("priceJMD", "2000");
                oneMastedYachtContent.SetValue("description", "<p>This is the product description.</p>");
                oneMastedYachtContent.SetValue("variants", "{\"variants\": [],\"variantGroupsOpen\":{}}");


                contentService.SaveAndPublishWithStatus(oneMastedYachtContent, raiseEvents: false);


                #endregion
                frontPageContent.SetValue("featuredProducts", string.Join(",", new List <string> {
                    "umb://document/" + summerYachtContent.Key.ToString().Replace("-", ""),
                    "umb://document/" + yachtWithSailsContent.Key.ToString().Replace("-", ""),
                    "umb://document/" + motorDrivenYachtContent.Key.ToString().Replace("-", ""),
                    "umb://document/" + oneMastedYachtContent.Key.ToString().Replace("-", ""),
                }));
                contentService.SaveAndPublishWithStatus(frontPageContent, raiseEvents: false);
            } catch (Exception ex) {
                LogHelper.Error <TeaCommerceStarterKitInstall>("Create content failed", ex);
            }

            #endregion


            return(true);
        }
        private IDataTypeDefinition CreateNestedContentDataType(IDataTypeDefinition archetypeDataType)
        {
            var name             = archetypeDataType.Name + " (NC)";
            var alias            = Alias(archetypeDataType.Name + "nc");  // TODO Umbraco method of creating aliases
            var existingDataType = _dataTypeService.GetDataTypeDefinitionByName(name);

            if (existingDataType != null)
            {
                return(existingDataType);
            }

            var preValue          = _dataTypeService.GetPreValuesByDataTypeId(archetypeDataType.Id).FirstOrDefault();
            var archetypePreValue = JsonConvert.DeserializeObject <ArchetypePreValue>(preValue);

            var contentType = new ContentType(-1);

            contentType.Name  = name;
            contentType.Alias = alias;

            foreach (var fieldset in archetypePreValue.Fieldsets)
            {
                var propertyGroup = new PropertyGroup();
                propertyGroup.Name = "Content";

                foreach (var prop in fieldset.Properties)
                {
                    var definition = _dataTypeService.GetDataTypeDefinitionById(prop.DataTypeGuid);
                    propertyGroup.PropertyTypes.Add(new PropertyType(definition)
                    {
                        Name = prop.Label, Alias = prop.Alias, Mandatory = prop.Required, Description = prop.HelpText
                    });
                }
                contentType.PropertyGroups.Add(propertyGroup);
            }
            _contentTypeService.Save(contentType);

            var dataType = new DataTypeDefinition(NestedContentAlias);

            dataType.Name = contentType.Name;

            var preValues = new Dictionary <string, PreValue>();

            preValues.Add("contentTypes", new PreValue(JsonConvert.SerializeObject(
                                                           new NestedContentPreValue[]
            {
                new NestedContentPreValue
                {
                    NcAlias      = contentType.Alias,
                    NcTabAlias   = "Content",
                    NameTemplate = archetypePreValue.Fieldsets.First().LabelTemplate
                }
            },
                                                           new JsonSerializerSettings {
                ContractResolver = _contractResolver
            })
                                                       ));
            preValues.Add("minItems", new PreValue("0"));
            preValues.Add("maxItems", new PreValue("0"));
            preValues.Add("confirmDeletes", new PreValue("0"));
            preValues.Add("showIcons", new PreValue("0"));
            preValues.Add("hideLabel", new PreValue(archetypePreValue.HidePropertyLabel ? "1" : "0"));

            _dataTypeService.SaveDataTypeAndPreValues(dataType, preValues);
            return(dataType);
        }