public void CreateStore(string storeName, string street, string zip, string city, string countryCode, string stateCode, double latitude, double longitude, int mapZoomLevel, string urlName, string phone, string imageTitle) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = String.Empty; // Set the culture name for the multilingual fields var cultureName = "en"; Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type shopType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Stores.Store"); DynamicContent shopItem = dynamicModuleManager.CreateDataItem(shopType); // This is how values for the properties are set shopItem.SetString("Title", storeName, cultureName); LibrariesManager libraryManager = LibrariesManager.GetManager(); var image = libraryManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Title == imageTitle); if (image != null) { shopItem.AddImage("StoreImage", image.Id); } Telerik.Sitefinity.GeoLocations.Model.Address myAddress = new Telerik.Sitefinity.GeoLocations.Model.Address(); myAddress.City = city; myAddress.CountryCode = countryCode; myAddress.StateCode = stateCode; myAddress.MapZoomLevel = mapZoomLevel; myAddress.Latitude = latitude; myAddress.Longitude = longitude; myAddress.Street = street; myAddress.Zip = zip; shopItem.SetValue("Address", myAddress); shopItem.SetString("UrlName", urlName, cultureName); shopItem.SetString("Phone", phone, cultureName); shopItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); shopItem.SetValue("PublicationDate", DateTime.Now); ILifecycleDataItem publishedFrontendContentItem = dynamicModuleManager.Lifecycle.Publish(shopItem); shopItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.SaveChanges(); }
/// <summary> /// Demonstrates how pressArticleItem is unpublished /// </summary> /// <param name="pressArticleItem">The press article item.</param> public void UNPublishPressArticle(ILifecycleDataItem pressArticleItem) { var providerName = string.Empty; if (ServerOperations.MultiSite().CheckIsMultisiteMode()) { providerName = "dynamicContentProvider"; } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); var liveDynamicItem = dynamicModuleManager.Lifecycle.GetLive(pressArticleItem); dynamicModuleManager.Lifecycle.Unpublish(liveDynamicItem); dynamicModuleManager.SaveChanges(); }
public void Unpublish(T item) { DynamicContent dynamicItem = item.DynamicContent; this.RequireMasterItem(dynamicItem); if (dynamicItem.GetWorkflowItemStatus() == "Published") { ILifecycleDataItem liveItem = this.manager.Lifecycle.GetLive(dynamicItem); if (liveItem != null) { this.Manager.Lifecycle.Unpublish(liveItem); dynamicItem.SetWorkflowStatus(this.Manager.Provider.ApplicationName, "Unpublished"); } } }
protected void AddRelatedItem(string fieldName, IDataItem relatedItem) { this.RequireEditMode(); ILifecycleDataItem lifecycleItem = relatedItem as ILifecycleDataItem; if (lifecycleItem != null) { if (lifecycleItem.Status != ContentLifecycleStatus.Master) { throw new InvalidOperationException("Relate only Master items. After publish relations to the Live items will be automatically created."); } } this.DynamicContent.CreateRelation(relatedItem, fieldName); }
private void MigrateMedia(string transactionName) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(parentItemProviderName, transactionName); var parentItems = dynamicModuleManager.GetDataItems(parentItemType); var allItemsCount = parentItems.Count(); var currentIndex = 1; var sliceIterator = parentItems.SliceQuery(1000); // this manager will serve only for checking if child items exist, it should work with childItemProvider var childItemsManager = ManagerBase.GetMappedManagerInTransaction(childItemType, childItemProviderName, transactionName); var managerType = ManagerBase.GetMappedManagerType(typeof(ContentLink)); var contentLinksManager = ManagerBase.GetManagerInTransaction(managerType, null, transactionName) as ContentLinksManager; var appName = contentLinksManager.Provider.ApplicationName; var librariesManager = LibrariesManager.GetManager(childItemProviderName); using (new ElevatedModeRegion(librariesManager)) { foreach (var slicedQuery in sliceIterator) { var currentQuery = slicedQuery; foreach (var parentItem in currentQuery) { // get selected items for current parent item var mediaContentLinks = parentItem.GetValue <ContentLink[]>(dynamicSelectorFieldName).ToArray(); foreach (var contentLink in mediaContentLinks) { ILifecycleDataItem currentItem = librariesManager.GetItemOrDefault(childItemType, contentLink.ChildItemId) as ILifecycleDataItem; if (currentItem != null) { var masterContentItem = librariesManager.Lifecycle.GetMaster(currentItem); this.AddRelationToItem(childItemsManager, contentLinksManager, appName, parentItem, masterContentItem.Id, contentLink.Ordinal, currentIndex, allItemsCount); } } currentIndex++; } TransactionManager.FlushTransaction(transactionName); } } currentIndex = 1; }
public void Upload(TorrentUploaderWidgetModel torrent) { string torrentExtention = Path.GetExtension(torrent.TorrentFile.FileName); string torrentTitle = Path.GetFileNameWithoutExtension(torrent.TorrentFile.FileName); Guid torrentFileId = this._documentService.UploadTorrentFile(torrentTitle, torrent.TorrentFile.InputStream, torrent.TorrentFile.FileName, torrentExtention, TORRENT_FILE_LIBRARY); string imageExtention = Path.GetExtension(torrent.CoverImage.FileName); string imageTitle = Path.GetFileNameWithoutExtension(torrent.CoverImage.FileName); Guid torrentImageId = this._imageService.Upload(imageTitle, torrent.CoverImage.InputStream, torrent.CoverImage.FileName, imageExtention, TORRENT_COVER_IMAGE_ALBUM); // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = String.Empty; // Set a transaction name and get the version manager var transactionName = "someTransactionName"; var versionManager = VersionManager.GetManager(null, transactionName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName); Type torrentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Torrents.Torrent"); DynamicContent torrentItem = dynamicModuleManager.CreateDataItem(torrentType); // This is how values for the properties are set torrentItem.SetValue("Title", torrent.Title); torrentItem.SetValue("Description", torrent.Description); LibrariesManager torrentFileManager = LibrariesManager.GetManager(); var torrentFileItem = torrentFileManager.GetDocuments().FirstOrDefault(i => i.Id == torrentFileId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (torrentFileItem != null) { torrentItem.CreateRelation(torrentFileItem, "TorrentFile"); } LibrariesManager imageManager = LibrariesManager.GetManager(); var imageItem = imageManager.GetImages().FirstOrDefault(i => i.Id == torrentImageId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (imageItem != null) { torrentItem.CreateRelation(imageItem, "Image"); } torrentItem.SetString("UrlName", Guid.NewGuid().ToString()); torrentItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); torrentItem.SetValue("PublicationDate", DateTime.UtcNow); // Create a version and commit the transaction in order changes to be persisted to data store torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, false); // We can now call the following to publish the item ILifecycleDataItem publishedTorrentItem = dynamicModuleManager.Lifecycle.Publish(torrentItem); // You need to set appropriate workflow status torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, true); TransactionManager.CommitTransaction(transactionName); }
/// <summary> /// Demonstrates how pressArticleItem is unpublished /// </summary> /// <param name="pressArticleItem">The press article item.</param> public void UNPublishPressArticle(ILifecycleDataItem pressArticleItem) { var providerName = string.Empty; DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); var liveDynamicItem = dynamicModuleManager.Lifecycle.GetLive(pressArticleItem); dynamicModuleManager.Lifecycle.Unpublish(liveDynamicItem); dynamicModuleManager.SaveChanges(); }
public string CreateSuccessStory(SuccessStoryViewModel submittedStory, string domain) { var message = String.Empty; try { var providerName = String.Empty; var transactionName = $"storyTransaction_{DateTime.Now}"; var versionManager = VersionManager.GetManager(null, transactionName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName); Type successStoryType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.SuccessStories.SuccessStory"); DynamicContent successStoryItem = dynamicModuleManager.CreateDataItem(successStoryType); successStoryItem.SetValue("Title", submittedStory.Title); successStoryItem.SetValue("Description", submittedStory.Description); successStoryItem.SetValue("SummaryDescription", submittedStory.SummaryDescription); successStoryItem.SetValue("ProductsUsed", submittedStory.ProductsUsed); successStoryItem.SetValue("Company", submittedStory.Company); successStoryItem.SetValue("CompanyWebsite", submittedStory.CompanyWebsite); successStoryItem.SetValue("Industry", submittedStory.Industry); LibrariesManager thumbnailManager = LibrariesManager.GetManager(); if (submittedStory.Thumbnail != null) { var fileStream = submittedStory.Thumbnail.InputStream; var imgId = Guid.NewGuid(); CreateImageWithNativeAPI(imgId, submittedStory.Title, fileStream, submittedStory.Thumbnail.FileName, Path.GetExtension(submittedStory.Thumbnail.FileName)); var thumbnailItem = thumbnailManager.GetImage(imgId); if (thumbnailItem != null) { successStoryItem.CreateRelation(thumbnailItem, "Thumbnail"); } } successStoryItem.SetString("UrlName", $"{submittedStory.Title}-{submittedStory.Company}"); successStoryItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); successStoryItem.SetValue("PublicationDate", DateTime.UtcNow); successStoryItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); versionManager.CreateVersion(successStoryItem, false); ILifecycleDataItem publishedCarItem = dynamicModuleManager.Lifecycle.Publish(successStoryItem); successStoryItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); versionManager.CreateVersion(successStoryItem, true); TransactionManager.CommitTransaction(transactionName); message = $"A new Success Story has been submitted. Take a look <a style=\"font-weight:bold;color:blue;\" href=\"{domain}/success-story-details{successStoryItem.ItemDefaultUrl.Value}\">here</a>"; } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(message); }
public void CreateTorrentWithPublish(CreateTorrentDto createTorrentDto) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = "OpenAccessProvider"; // Set a transaction name and get the version manager var transactionName = "someTransactionName"; var versionManager = VersionManager.GetManager(null, transactionName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName); Type torrentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Torrents.Torrent"); DynamicContent torrentItem = dynamicModuleManager.CreateDataItem(torrentType); // This is how values for the properties are set torrentItem.SetValue("AdditionalInfo", createTorrentDto.AdditionalInfo); torrentItem.SetValue("Description", createTorrentDto.Description); torrentItem.SetValue("Title", createTorrentDto.Title); torrentItem.SetValue("CreationDate", DateTime.Now); List <Guid> taxonIds = _taxonomyService.GetTaxonIdsByTaxonomy(createTorrentDto.Genres, Constants.GenresTaxonomyName); if (taxonIds.Any()) { torrentItem.Organizer.AddTaxa(Constants.GenresTaxonomyName, taxonIds.ToArray()); } Image imageFileItem = _imageService.CreateImageWithNativeAPI(createTorrentDto.ImageDto); if (imageFileItem != null) { // This is how we relate an item torrentItem.CreateRelation(imageFileItem, "ImageFile"); } Document torrentFileItem = _documentService.CreateDocumentNativeAPI(createTorrentDto.DocumentDto); if (torrentFileItem != null) { // This is how we relate an item torrentItem.CreateRelation(torrentFileItem, "TorrentFile"); } torrentItem.SetString("UrlName", $"{createTorrentDto.Title}{torrentItem.Id}"); torrentItem.SetValue("Owner", ClaimsManager.GetCurrentIdentity().UserId); torrentItem.SetValue("PublicationDate", DateTime.UtcNow); torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, false); // We can now call the following to publish the item ILifecycleDataItem publishedTorrentItem = dynamicModuleManager.Lifecycle.Publish(torrentItem); // You need to set appropriate workflow status torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, true); // Now the item is published and can be seen in the page // Commit the transaction in order for the items to be actually persisted to data store TransactionManager.CommitTransaction(transactionName); }