Last active
February 23, 2019 13:26
-
-
Save VesselinVassilev/dd63d3b7d02e2fb57dc6370aca4a4c10 to your computer and use it in GitHub Desktop.
Create DynamicContent Item on Multiple Languages at once. Tested in 9.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void btn_Click(object sender, EventArgs e) | |
{ | |
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); | |
Type personType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.People.Person"); | |
DynamicContent personItem = dynamicModuleManager.CreateDataItem(personType); | |
personItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); | |
personItem.SetValue("PublicationDate", DateTime.Now); | |
//to prevent adding 3 items in DB | |
dynamicModuleManager.Lifecycle.Publish(personItem); | |
dynamicModuleManager.SaveChanges(); | |
CultureInfo[] languages = SystemManager.CurrentContext.AppSettings.DefinedFrontendLanguages; | |
foreach (var lang in languages) | |
{ | |
Thread.CurrentThread.CurrentUICulture = lang; | |
personItem = dynamicModuleManager.Lifecycle.CheckOut(personItem, lang) as DynamicContent; | |
personItem.SetString("Title", string.Concat("Some Title ", lang), lang); | |
personItem.SetString("FullName", string.Concat("Some FullName ", lang), lang); | |
personItem.SetValue("Gender", "Male"); | |
personItem.SetString("UrlName", string.Concat("SomeUrlName", lang), lang); | |
personItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published", lang); | |
personItem = dynamicModuleManager.Lifecycle.CheckIn(personItem) as DynamicContent; | |
dynamicModuleManager.Lifecycle.Publish(personItem); | |
} | |
dynamicModuleManager.SaveChanges(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment