Ejemplo n.º 1
0
        private async Task <ContentItemVariantModel <UserModel> > CreateUserVariant(UserModel userModel, ContentItemIdentifier itemIdentifier)
        {
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename("default");
            ContentItemVariantIdentifier variantIdentifier  = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

            ContentItemVariantModel <UserModel> responseVariant = await managementClient.UpsertContentItemVariantAsync <UserModel>(variantIdentifier, userModel);

            return(responseVariant);
        }
Ejemplo n.º 2
0
        public void BuildContentItemVariantsUrl_ItemCodenameVariantCodename_ReturnsCorrectUrl()
        {
            var itemIdentifier    = ContentItemIdentifier.ByCodename(ITEM_CODENAME);
            var variantIdentifier = LanguageIdentifier.ByCodename(VARIANT_CODENAME);
            var identifier        = new ContentItemVariantIdentifier(itemIdentifier, variantIdentifier);
            var actualUrl         = _builder.BuildVariantsUrl(identifier);
            var expectedUrl       = $"{ENDPOINT}/projects/{PROJECT_ID}/items/codename/{ITEM_CODENAME}/variants/codename/{VARIANT_CODENAME}";

            Assert.Equal(expectedUrl, actualUrl);
        }
Ejemplo n.º 3
0
        internal static async Task <ContentItemVariantModel> PrepareTestVariant(ContentManagementClient client, string languageCodename, object elements, ContentItemModel item)
        {
            var addedItemIdentifier                = ContentItemIdentifier.ByCodename(item.CodeName);
            var addedLanguageIdentifier            = LanguageIdentifier.ByCodename(languageCodename);
            var addedContentItemLanguageIdentifier = new ContentItemVariantIdentifier(addedItemIdentifier, addedLanguageIdentifier);
            var variantUpdateModel = new ContentItemVariantUpsertModel()
            {
                Elements = elements
            };

            return(await client.UpsertContentItemVariantAsync(addedContentItemLanguageIdentifier, variantUpdateModel));
        }
Ejemplo n.º 4
0
        public static (ContentItemIdentifier, LanguageIdentifier, ContentItemVariantIdentifier) GetIdentifiers(string ContentItemCodeName)
        {
            //Retrieive an ItemIdentifier by codename of the content item we want to create a new version of
            ContentItemIdentifier itemIdentifier = ContentItemIdentifier.ByCodename(ContentItemCodeName);

            //Retreive the language identifier of the content item in Konent for the content item (even if we only have one)
            LanguageIdentifier langIdentifier = LanguageIdentifier.ByCodename(RowlingAppConstants.DefaultLanguageCode);

            //Retreive the content item language variant of the content item we want to update (the real unique identifier)
            ContentItemVariantIdentifier identifier = new ContentItemVariantIdentifier(itemIdentifier, langIdentifier);

            return(itemIdentifier, langIdentifier, identifier);
        }
Ejemplo n.º 5
0
        public async Task <string> UpsertTaxonomy(Movie movie, string listing_prediction)
        {
            MovieImport stronglyTypedElements = new MovieImport
            {
                ListedIn = new[] { TaxonomyTermIdentifier.ByCodename(listing_prediction) }
            };

            // Specifies the content item and the language variant
            ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ByCodename(movie.System.Codename);
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename(movie.System.Language);
            ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

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

            return(response.Elements.Title + " updated.");
        }
Ejemplo n.º 6
0
        private async Task <ContentItemVariantModel <ConversationModel> > UpsertConversationVariant(ConversationModel conversation, ContentItemIdentifier itemIdentifier)
        {
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename("default");
            ContentItemVariantIdentifier variantIdentifier  = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

            ContentItemVariantModel <ConversationModel> responseVariant = new ContentItemVariantModel <ConversationModel> {
            };

            try
            {
                responseVariant = await managementClient.UpsertContentItemVariantAsync <ConversationModel>(variantIdentifier, conversation);
            }
            catch (Exception e)
            {
                logger.Debug(e, "Failed to create conversation variant.");
            }
            return(responseVariant);
        }
Ejemplo n.º 7
0
        public async static Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext context)
        {
            try
            {
                var config = new ConfigurationBuilder()
                             .SetBasePath(context.FunctionAppDirectory)
                             .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                             .AddEnvironmentVariables()
                             .Build();


                string strLanguageCode = config["KenticoCloudLanguageCode"];

                ContentManagementOptions options = new ContentManagementOptions
                {
                    ProjectId = config["KenticoCloudProjectID"],
                    ApiKey    = config["KenticoCloudContentManagementAPIKey"]
                };

                // Initializes an instance of the ContentManagementClient client
                ContentManagementClient client = new ContentManagementClient(options);

                // Defines the content elements to update
                Task <string> body = new StreamReader(req.Body).ReadToEndAsync();

                ArticleModel NewArticleModel = JsonConvert.DeserializeObject <ArticleModel>(body.Result.ToString());

                // Specifies the content item and the language variant
                ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ByCodename(NewArticleModel.OriginalCodename);
                LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename(strLanguageCode);
                ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

                // Upserts a language variant of your content item
                ContentItemVariantModel <Article> responseUpdate = await client.UpsertContentItemVariantAsync <Article>(identifier, NewArticleModel.NewArticle);

                return((ActionResult) new OkObjectResult($"SUCCESS: Language variant added!"));
            }
            catch (Exception ex)
            {
                return(new OkObjectResult("FAILURE: " + ex.Message));
            }
        }