Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap content item insert/upsert #12

Open
lukasturek opened this issue Jun 26, 2018 · 1 comment
Open

Wrap content item insert/upsert #12

lukasturek opened this issue Jun 26, 2018 · 1 comment
Labels
enhancement groomed The issue has been groomed and should be in a good shape. help wanted up-for-grabs

Comments

@lukasturek
Copy link

lukasturek commented Jun 26, 2018

Motivation

In order to create a content there is a lot of work needed - to create a content item model, create an item itself without any data, and create the item variant. The distinction between content item and content item variant does not have to be obvious for newcomers. And all of this takes many lines of code as can be seen from the example:

// Creates an instance of the Content Management client
ContentManagementClient client = new ContentManagementClient(options);

// Defines the content item to import
ContentItemCreateModel item = new ContentItemCreateModel()
{
    Name = "On Roasts",
    Type = ContentTypeIdentifier.ByCodename("article"),
    SitemapLocations = new[] { SitemapNodeIdentifier.ByCodename("articles") }
};

// Adds the content item to your project in Kentico Cloud
ContentItemModel response = await client.CreateContentItemAsync(item);

// Defines the content elements to update
ArticleModel stronglyTypedElements = new ArticleModel
{
    Title = "On Roasts",
    PostDate = new DateTime(2017, 7, 4),
    BodyCopy = @"
        <h1>Light Roasts</h1>
        <p>Usually roasted for 6 - 8 minutes or simply until achieving a light brown color. This method
        is used for milder coffee  varieties and for coffee tasting. This type of roasting allows the natural
        characteristics of each coffee to show. The aroma of coffees produced from light roasts is usually
        more intense.The cup itself is more acidic and the concentration of caffeine is higher.</p>
    ",
    RelatedArticles = new [] { ContentItemIdentifier.ByCodename("which_brewing_fits_you_") },
    UrlPattern = "on-roasts",
    Personas = new [] { TaxonomyTermIdentifier.ByCodename("barista") }
};

// Specifies the content item and the language variant
ContentItemIdentifier itemIdentifier = ContentItemIdentifier.ByCodename("on_roasts");
LanguageIdentifier languageIdentifier = LanguageIdentifier.ByCodename("en-US");
ContentItemVariantIdentifier identifier = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

// Upserts a language variant of your content item
ContentItemVariantModel<ArticleModel> response = await client.UpsertContentItemVariantAsync<ArticleModel>(identifier, stronglyTypedElements);

Design guidelines

The suggestion would be to create a wrapper, so the content item variant can be created/updated using a single method.

The approach would be similar to the Migration Tool by @MilanLund.

@petrsvihlik
Copy link
Contributor

@ChristopherJennings would you be interested in implementing this? (or someone from the consulting team?)

@JanLenoch JanLenoch added the groomed The issue has been groomed and should be in a good shape. label Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement groomed The issue has been groomed and should be in a good shape. help wanted up-for-grabs
Projects
None yet
Development

No branches or pull requests

3 participants