コード例 #1
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.");
        }
コード例 #2
0
        private static void ImportMovies(string folderPath, ContentManagementClient client)
        {
            foreach (var movie in DatabaseEntry.CreateFromFolder(Path.Combine(folderPath, "Movies")))
            {
                Console.WriteLine($"Importing {movie.GetText("Name")}");

                var imageExternalIds = ImportMoviePhotos(movie, folderPath, client);

                var externalId = $"Movie - {movie.ExternalId}";

                var item = new ContentItemUpsertModel
                {
                    Name             = movie.GetText("Name"),
                    Type             = ContentTypeIdentifier.ByCodename("movie"),
                    SitemapLocations = movie.GetListItems("Sitemap location").Select(x => SitemapNodeIdentifier.ByCodename(GetCodename(x)))
                };

                client.UpsertContentItemByExternalIdAsync(externalId, item);

                var itemIdentifier     = ContentItemIdentifier.ByExternalId(externalId);
                var languageIdentifier = LanguageIdentifier.DEFAULT_LANGUAGE;

                var variant = new ContentItemVariantUpsertModel
                {
                    Elements = new
                    {
                        name         = movie.GetText("Name"),
                        description  = movie.GetText("Description"),
                        synopsis     = movie.GetText("Synopsis"),
                        release_date = movie.GetDateTime("Release date"),
                        genre        = movie.GetListItems("Genres").Select(x => TaxonomyTermIdentifier.ByCodename(GetCodename(x))),
                        cast         = movie.GetListItems("Cast").Select(x => ContentItemIdentifier.ByExternalId($"Actor - {x}")),
                        imdb_rating  = movie.GetNumber("IMDB rating"),
                        rating       = new [] { MultipleChoiceOptionIdentifier.ByCodename(GetCodename(movie.GetText("Rating"))) },
                        slug         = movie.GetText("Slug"),
                        photos       = imageExternalIds.Select(imageExternalId => AssetIdentifier.ByExternalId(imageExternalId))
                    },
                };

                client.UpsertContentItemVariantAsync(new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier), variant);
            }
        }
コード例 #3
0
        /// <summary>
        /// Adds language variant content to the content item with the supplied codename
        /// </summary>
        /// <param name="codename">Codename of the content item needed</param>
        /// <returns></returns>
        public async Task <Guid> CreateItemVariantAsync(string codename)
        {
            const string htmlMarkup = @"<h1>Some content</h1>
                        <p>This is the content</p>";

            if (!IsValidHtml(htmlMarkup))
            {
                return(Guid.Empty);
            }

            var content = new SimplePage
            {
                PageTitle   = "Test import",
                PageContent = htmlMarkup,
                DishColour  = new[]
                {
                    TaxonomyTermIdentifier.ByCodename("green")
                },
                PageTeaser = new AssetIdentifier[0]
            };

            // Specifies the content item and the language variant
            ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ByCodename(codename);
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.DEFAULT_LANGUAGE;
            ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier: itemIdentifier, languageIdentifier: languageIdentifier);

            // Upserts a language variant of your content item
            try
            {
                ContentItemVariantModel <SimplePage> response = await _managementClient.UpsertContentItemVariantAsync <SimplePage>(identifier, content);

                return(response.Item.Id);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: {ex.Message}");
                return(Guid.Empty);
            }
        }