コード例 #1
0
ファイル: ContentTests.cs プロジェクト: gnilesh4/piranha.core
        public override async Task InitializeAsync()
        {
            using (var api = CreateApi())
            {
                Piranha.App.Init(api);

                // Add the content type
                var builder = new ContentTypeBuilder(api)
                              .AddType(typeof(MyContent));
                await builder.BuildAsync();

                // Add a secondary language
                await api.Languages.SaveAsync(new Language
                {
                    Id      = ID_LANG,
                    Title   = "Second Language",
                    Culture = "sv-SE"
                });

                // Add some default content
                var content1 = await MyContent.CreateAsync(api);

                content1.Id              = ID_1;
                content1.Title           = "My first content";
                content1.Excerpt         = "My first excerpt";
                content1.MainDescription = "My first description";

                await api.Content.SaveAsync(content1);

                var content2 = await MyContent.CreateAsync(api);

                content2.Id              = ID_2;
                content2.Title           = "My second content";
                content2.Excerpt         = "My second excerpt";
                content2.MainDescription = "My second description";

                await api.Content.SaveAsync(content2);

                var content3 = await MyContent.CreateAsync(api);

                content3.Id              = ID_3;
                content3.Title           = "My third content";
                content3.Excerpt         = "My third excerpt";
                content3.MainDescription = "My third description";

                await api.Content.SaveAsync(content3);

                // Now let's translate content 1
                content1.Title           = "Mitt första innehåll";
                content1.Excerpt         = "Min första sammanfattning";
                content1.MainDescription = "Min första beskrivning";

                await api.Content.SaveAsync(content1, ID_LANG);
            }
        }