public static bool GetBoolValueOrDefault(DynamicContent item, string property, bool defaultValue = false) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToBoolean(propertyValue); }
public static decimal GetDecimalValueOrDefault(DynamicContent item, string property, decimal defaultValue = 0) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToDecimal(propertyValue); }
public static DateTime GetDateTimeValueOrDefault(DynamicContent item, string property, DateTime defaultValue = default(DateTime)) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToDateTime(propertyValue); }
public static int GetIntChoiseValueOrDefault(DynamicContent item, string property, int defaultValue = 0) { ChoiceOption propertyValue = item.GetValue(property) as ChoiceOption; if (propertyValue == null) { return defaultValue; } return Convert.ToInt32(propertyValue.PersistedValue); }
/// <summary> /// Gets the related media URL. /// </summary> /// <param name="item">The DynamicContent.</param> /// <returns>The media's relative Url</returns> public static string GetRelatedMediaUrl(DynamicContent item, string fieldName) { var relatedItem = item.GetRelatedItems(fieldName).FirstOrDefault(); if (relatedItem != null) { var imageId = relatedItem.Id; LibrariesManager manager = LibrariesManager.GetManager(); Telerik.Sitefinity.Libraries.Model.Image image = manager.GetImage(imageId); if (image != null) return image.MediaUrl; } return null; }
private CarViewModel GetViewModel(DynamicContent dContent) { CarViewModel viewModel = new CarViewModel(); viewModel.Id = dContent.Id; viewModel.Title = dContent.GetString("Title").Value; viewModel.Info = dContent.GetString("CarInfo").Value; if (dContent.GetRelatedItemsCountByField("CarImages") > 0) { viewModel.Image = dContent.GetRelatedItems<Image>("CarImages").FirstOrDefault(); } return viewModel; }
/// <inheritdoc /> public static ImageViewModel GetRelatedImage(DynamicContent item, string fieldName) { if (item == null) throw new ArgumentNullException("item", "Item cannot be null"); if (String.IsNullOrEmpty(fieldName)) throw new ArgumentException(message: "Value cannot be null or empty", paramName: "fieldName"); ImageViewModel imageModel = new ImageViewModel(); var image = item.GetRelatedItems<Image>(fieldName).FirstOrDefault(); if (image != null) { imageModel.Title = image.Title; imageModel.ThumbnailUrl = image.GetDefaultUrl(); imageModel.ImageUrl = image.MediaUrl; imageModel.AlternativeText = image.AlternativeText; } return imageModel; }
/// <inheritdoc /> public static DocumentViewModel GetRelatedDocument(DynamicContent item, string fieldName) { if (item == null) throw new ArgumentNullException("item", "Item cannot be null"); if (String.IsNullOrEmpty(fieldName)) throw new ArgumentException(message: "Value cannot be null or empty", paramName: "fieldName"); DocumentViewModel documentModel = new DocumentViewModel(); var document = item.GetRelatedItems<Document>(fieldName).FirstOrDefault(); if (document != null) { documentModel.Title = document.Title; documentModel.DownloadUrl = document.MediaUrl; documentModel.Description = document.Description; documentModel.Id = document.Id; documentModel.Extension = document.Extension; } return documentModel; }
public T BuildTypedItem(DynamicContent dynamicItem) { return(converter.BuildTypedItem <T>(dynamicItem)); }
public IQueryable <string> GetRelatedClassifications(DynamicContent content, string relatedField, string taxonomyName) { var clasifications = GetClasifications(content, relatedField, taxonomyName); return(clasifications.Select(c => $"{c.Title}")); }
public T GetFieldValue <T>(DynamicContent contentItem, string fieldName) { return(contentItem != null && contentItem.DoesFieldExist(fieldName) ? contentItem.GetValue <T>(fieldName) : default);
public StructuredDataInjectionConverterTests() { fakeDynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); fakeDynamicContentItem = A.Dummy <DynamicContent>(); }
public static string GetStringValueOrDefault(DynamicContent item, string property, string defaultValue = null) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return propertyValue.ToString(); }
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); }
public FrameworkSkillConverterTests() { fakeDynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); fakeDynamicContentItem = A.Dummy <DynamicContent>(); }
private void DriversPage(object sender, RoutedEventArgs e) { DynamicContent.Navigate(new Uri("Views/Drivers.xaml", UriKind.Relative)); }
private ContentLink GetRelation(ContentLinksManager contentLinksManager, string appName, DynamicContent parentItem, Guid childItemId) { var relationId = parentItem.Status == ContentLifecycleStatus.Master ? parentItem.Id : parentItem.OriginalContentId; var relationFunc = new Func <ContentLink, bool>((c) => c.ParentItemId == relationId && c.ParentItemType == this.ParentItemTypeName && c.ParentItemProviderName == this.ParentItemProviderName && c.ComponentPropertyName == this.RelatedDataFieldName && c.ChildItemId == childItemId && c.ChildItemProviderName == this.ChildItemProviderName && c.ChildItemType == this.ChildItemTypeName); var masterRelation = contentLinksManager.GetContentLinks().Where(c => c.ApplicationName == appName) .Where(relationFunc).FirstOrDefault(); // check for relation in dirty items if (masterRelation == null) { masterRelation = contentLinksManager.Provider.GetDirtyItems().OfType <ContentLink>().Where(c => c.ApplicationName == appName) .Where(relationFunc).FirstOrDefault(); } return(masterRelation); }
private void AddRelationToItem(IManager childItemsDynamicModuleManager, ContentLinksManager contentLinksManager, string appName, DynamicContent parentItem, Guid childItemId, float ordinal, int currentItemIndex = 0, int allCount = 0) { using (new ElevatedModeRegion(childItemsDynamicModuleManager)) { var childItem = childItemsDynamicModuleManager.GetItemOrDefault(this.ChildItemType, childItemId) as IDataItem; if (childItem != null) { var relation = parentItem.CreateRelation(childItem, this.RelatedDataFieldName); this.Log(String.Format(logRelationCreated, parentItem.Id, parentItem.Status, childItemId, (parentItem as IHasTitle).GetTitle(), currentItemIndex, allCount)); //Related Data API will be modified to return the created content link or will receive ordinal as parameter. But for now (7.0.5100), we have to get the content link this way. if (relation != null) { relation.Ordinal = ordinal; } } else { // log that item with that id from that provider and type was not found this.Log(String.Format(logRelatedItemDoesntExist, childItemId)); this.Log(String.Format(logRelatedItemDoesntExist, childItemId), true); } } this.Log(String.Format(logRelatedItemExist, parentItem.Id, currentItemIndex, allCount)); }
public void Delete(DynamicContent entity) { throw new NotImplementedException(); }
public AuthorViewModel(DynamicContent author) : base(author) { }
private void detach_DynamicContents(DynamicContent entity) { this.SendPropertyChanging(); entity.User = null; }
private void attach_DynamicContents(DynamicContent entity) { this.SendPropertyChanging(); entity.User = this; }
public ApprenticeVacancyConverterTests() { dynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); dummyDynamicContent = A.Dummy <DynamicContent>(); }
public void DynamicWidgets_VerifySelectedItemsFunctionalityWithSortDescending() { string sortExpession = "Title DESC"; string[] selectedDynamicTitles = { "Title2", "Title7", "Title5" }; string[] expectedDynamicTitles = { "Title7", "Title5", "Title2" }; try { for (int i = 0; i < 10; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticleItem("Title" + i, "Title" + i + "Url"); } var dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SelectionMode = SelectionMode.SelectedItems; dynamicController.Model.SortExpression = sortExpession; var selectedDynamicItems = new DynamicContent[3]; for (int i = 0; i < selectedDynamicTitles.Count(); i++) { selectedDynamicItems[i] = dynamicCollection.FirstOrDefault<DynamicContent>(n => n.UrlName == (selectedDynamicTitles[i] + "Url")); } //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]" dynamicController.Model.SerializedSelectedItemsIds = "[\"" + selectedDynamicItems[0].Id.ToString() + "\"," + "\"" + selectedDynamicItems[1].Id.ToString() + "\"," + "\"" + selectedDynamicItems[2].Id.ToString() + "\"]"; var modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: null, page: 1); var dynamicItems = modelItems.Items.ToList(); int itemsCount = dynamicItems.Count; for (int i = 0; i < itemsCount; i++) { Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(expectedDynamicTitles[i]), "The item with this title was not found!"); } dynamicController.Model.SelectionMode = SelectionMode.AllItems; modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: null, page: 1); dynamicItems = modelItems.Items.ToList(); int lastIndex = 9; for (int i = 0; i < 10; i++) { Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(this.dynamicTitle + lastIndex), "The item with this title was not found!"); lastIndex--; } } finally { ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); } }
private DataModel Typify(DynamicContent dynamicItem) { return(new DataModel(dynamicItem)); }
public void PublishPressArticleWithSpecificDate(DynamicContent pressArticleItem, DateTime specificDate) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = string.Empty; DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); ////We can set a date and time in the future, for the item to be published dynamicModuleManager.Lifecycle.PublishWithSpecificDate(pressArticleItem, specificDate); // You need to call SaveChanges() in order for the items to be actually persisted to data store dynamicModuleManager.SaveChanges(); }
partial void InsertDynamicContent(DynamicContent instance);
// This overload is used for LINQ expressions when we don't want to include // anything, as you can't have optional params in LINQ expressions. public static T MapTo <T>(this DynamicContent content) where T : new() => content.MapTo <T>(null);
private IEnumerable <FrameworkSkillItem> GetRelatedSkillsData(DynamicContent jobProfileContent, DynamicContent content, string relatedField) { var relatedSkillsData = new List <FrameworkSkillItem>(); if (jobProfileContent.ApprovalWorkflowState == Constants.WorkflowStatusDraft && content.GetType().Name == Constants.SOCSkillsMatrix) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var liveItem = dynamicModuleManager.Lifecycle.GetLive(content); content = dynamicModuleManager.GetDataItem(content.GetType(), liveItem.Id); } var relatedItems = dynamicContentExtensions.GetRelatedItems(content, relatedField); if (relatedItems != null) { foreach (var relatedItem in relatedItems) { relatedSkillsData.Add(new FrameworkSkillItem { Id = dynamicContentExtensions.GetFieldValue <Guid>(relatedItem, relatedItem.GetContentItemIdKey()), Title = dynamicContentExtensions.GetFieldValue <Lstring>(relatedItem, nameof(FrameworkSkillItem.Title)), Description = dynamicContentExtensions.GetFieldValue <Lstring>(relatedItem, nameof(FrameworkSkillItem.Description)), ONetElementId = dynamicContentExtensions.GetFieldValue <Lstring>(relatedItem, nameof(FrameworkSkillItem.ONetElementId)) }); } } return(relatedSkillsData); }
partial void DeleteDynamicContent(DynamicContent instance);
private IEnumerable <RelatedSocCodeItem> GetRelatedSocsData(DynamicContent jobprofileContent, DynamicContent content, string relatedField) { var relatedSocsData = new List <RelatedSocCodeItem>(); if (jobprofileContent.ApprovalWorkflowState == Constants.WorkflowStatusDraft && content.GetType().Name == Constants.SOCSkillsMatrix) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var liveItem = dynamicModuleManager.Lifecycle.GetLive(content); content = dynamicModuleManager.GetDataItem(content.GetType(), liveItem.Id); } var relatedItems = dynamicContentExtensions.GetRelatedItems(content, relatedField); if (relatedItems != null) { foreach (var relatedItem in relatedItems) { relatedSocsData.Add(GetRelatedSocData(jobprofileContent, relatedItem)); } } return(relatedSocsData); }
public JobProfileOverloadForWhatItTakesConverterTests() { fakeDynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); fakeDynamicContentItem = A.Dummy <DynamicContent>(); }
private RelatedSocCodeItem GetRelatedSocData(DynamicContent jobprofileContent, DynamicContent content) { var socCodes = new RelatedSocCodeItem { Id = dynamicContentExtensions.GetFieldValue <Guid>(content, content.GetContentItemIdKey()), SOCCode = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(SocCode.SOCCode)).ToLower() }; return(socCodes); }
public HowToBecome ConvertFrom(DynamicContent content) { var isCadReady = dynamicContentExtensions.GetFieldValue <bool>(content, nameof(HowToBecome.IsHTBCaDReady)); return(!isCadReady ? new HowToBecome() : new HowToBecome { IsHTBCaDReady = true, IntroText = dynamicContentExtensions.GetFieldValue <Lstring>(content, IntroTextField), FurtherRoutes = new FurtherRoutes { // OTHER Work = dynamicContentExtensions.GetFieldValue <Lstring>(content, WorkField), Volunteering = dynamicContentExtensions.GetFieldValue <Lstring>(content, VolunteeringField), DirectApplication = dynamicContentExtensions.GetFieldValue <Lstring>(content, DirectApplicationField), OtherRoutes = dynamicContentExtensions.GetFieldValue <Lstring>(content, OtherRoutesField) }, FurtherInformation = new MoreInformation { ProfessionalAndIndustryBodies = dynamicContentExtensions.GetFieldValue <Lstring>(content, ProfessionalAndIndustryBodiesField), CareerTips = dynamicContentExtensions.GetFieldValue <Lstring>(content, CareerTipsField), FurtherInformation = dynamicContentExtensions.GetFieldValue <Lstring>(content, FurtherInformationField) }, RouteEntries = new List <RouteEntry> { // UNIVERSITY new RouteEntry { RouteName = RouteEntryType.University, RouteSubjects = dynamicContentExtensions.GetFieldValue <Lstring>(content, UniversityRelevantSubjectsField), FurtherRouteInformation = dynamicContentExtensions.GetFieldValue <Lstring>(content, UniversityFurtherRouteInfoField), RouteRequirement = classificationsRepository.GetRelatedClassifications(content, UniversityRequirementsField, UniversityRequirementsField).FirstOrDefault(), EntryRequirements = GetEntryRequirements(content, RelatedUniversityRequirementField), MoreInformationLinks = GetRelatedLinkItems(content, RelatedUniversityLinksField) }, // College new RouteEntry { RouteName = RouteEntryType.College, RouteSubjects = dynamicContentExtensions.GetFieldValue <Lstring>(content, CollegeRelevantSubjectsField), FurtherRouteInformation = dynamicContentExtensions.GetFieldValue <Lstring>(content, CollegeFurtherRouteInfoField), RouteRequirement = classificationsRepository.GetRelatedClassifications(content, CollegeRequirementsField, CollegeRequirementsField).FirstOrDefault(), EntryRequirements = GetEntryRequirements(content, RelatedCollegeRequirementField), MoreInformationLinks = GetRelatedLinkItems(content, RelatedCollegeLinksField) }, // Apprenticeship new RouteEntry { RouteName = RouteEntryType.Apprenticeship, RouteSubjects = dynamicContentExtensions.GetFieldValue <Lstring>(content, ApprenticeshipRelevantSubjectsField), FurtherRouteInformation = dynamicContentExtensions.GetFieldValue <Lstring>(content, ApprenticeshipFurtherRouteInfoField), RouteRequirement = classificationsRepository.GetRelatedClassifications(content, ApprenticeshipRequirementsField, ApprenticeshipRequirementsField).FirstOrDefault(), EntryRequirements = GetEntryRequirements(content, RelatedApprenticeshipRequirementField), MoreInformationLinks = GetRelatedLinkItems(content, RelatedApprenticeshipLinksField) } }, Registrations = GetRegistrations(content, RelatedRegistrationsField), }); }
public JobProfileMessage ConvertFrom(DynamicContent content) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var jobProfileMessage = new JobProfileMessage { JobProfileId = dynamicContentExtensions.GetFieldValue <Guid>(content, content.GetContentItemIdKey()), Title = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.Title)), WidgetContentTitle = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.WidgetContentTitle)), AlternativeTitle = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.AlternativeTitle)), Overview = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.Overview)), SalaryStarter = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.SalaryStarter)), SalaryExperienced = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.SalaryExperienced)), MinimumHours = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.MinimumHours)), MaximumHours = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.MaximumHours)), CareerPathAndProgression = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.CareerPathAndProgression)), CourseKeywords = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.CourseKeywords)), //Need to use a string to get the content cannot use JobProfileMessage.JobProfileCategories as this is already used in the search //index and we will get a clash UrlName = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.UrlName)), IsImported = dynamicContentExtensions.GetFieldValue <bool>(content, nameof(JobProfileMessage.IsImported)), // How To Become section HowToBecomeData = htbContentPropertyConverter.ConvertFrom(content), RelatedCareersData = GetRelatedCareersData(content, Constants.RelatedCareerProfiles), Restrictions = GetRestrictions(content, RelatedRestrictionsField), OtherRequirements = dynamicContentExtensions.GetFieldValue <Lstring>(content, OtherRequirementsField), DynamicTitlePrefix = dynamicContentExtensions.GetFieldChoiceLabel(content, nameof(JobProfileMessage.DynamicTitlePrefix)), DigitalSkillsLevel = dynamicContentExtensions.GetFieldChoiceLabel(content, nameof(JobProfileMessage.DigitalSkillsLevel)), }; jobProfileMessage.IncludeInSitemap = content.IncludeInSitemap; //What You will do section jobProfileMessage.WhatYouWillDoData = GetWYDRelatedDataForJobProfiles(content); //Related Skills Data jobProfileMessage.SocSkillsMatrixData = GetSocSkillMatrixItems(content, Constants.RelatedSkills); //Get SOC Code data var socItem = dynamicContentExtensions.GetRelatedItems(content, Constants.SocField, 1).FirstOrDefault(); //SocCode Data jobProfileMessage.SocCodeData = GenerateSocData(content, socItem); //Working Pattern Details jobProfileMessage.WorkingPatternDetails = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.WorkingPatternDetail)); //Working Hours Details jobProfileMessage.WorkingHoursDetails = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.WorkingHoursDetail)); //Working Pattern jobProfileMessage.WorkingPattern = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.WorkingPattern)); //Hidden Alternative Title jobProfileMessage.HiddenAlternativeTitle = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.HiddenAlternativeTitle)); //Job Profile Specialism jobProfileMessage.JobProfileSpecialism = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.JobProfileSpecialism)); if (socItem != null) { jobProfileMessage.SocLevelTwo = dynamicContentExtensions.GetFieldValue <Lstring>(socItem, Constants.SOCCode).ToString().Substring(0, 2); } jobProfileMessage.LastModified = dynamicContentExtensions.GetFieldValue <DateTime>(content, nameof(JobProfileMessage.LastModified)); jobProfileMessage.CanonicalName = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.UrlName)).ToLower(); jobProfileMessage.JobProfileCategories = GetJobCategories(dynamicContentExtensions.GetFieldValue <IList <Guid> >(content, RelatedJobProfileCategoriesField)); return(jobProfileMessage); }
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); }
/// <summary> /// Transform content to a edit model. /// </summary> /// <param name="content">The dynamic content object</param> /// <returns>Edit model</returns> private async Task <ContentEditModel> Transform(DynamicContent content) { var config = new Config(_api); var type = App.ContentTypes.GetById(content.TypeId); var languages = await _api.Languages.GetAllAsync(); var categories = await _api.Content.GetAllCategoriesAsync(type.Group); var tags = await _api.Content.GetAllTagsAsync(type.Group); var model = new ContentEditModel { Id = content.Id, TypeId = content.TypeId, PrimaryImage = content.PrimaryImage, Title = content.Title, Excerpt = content.Excerpt, UseBlocks = type.UseBlocks, UseCategory = type.UseCategory, UseTags = type.UseTags, UsePrimaryImage = type.UsePrimaryImage, UseExcerpt = type.UseExcerpt, UseHtmlExcerpt = config.HtmlExcerpt, UseTranslations = languages.Count() > 1, Languages = languages, SelectedCategory = type.UseCategory ? content.Category?.Title : null, SelectedTags = type.UseTags ? content.Tags.Select(t => t.Title).ToList() : null, Categories = categories.Select(c => c.Title).ToList(), Tags = tags.Select(c => c.Title).ToList() }; foreach (var regionType in type.Regions) { var region = new Models.Content.RegionModel { Meta = new Models.Content.RegionMeta { Id = regionType.Id, Name = regionType.Title, Description = regionType.Description, Placeholder = regionType.ListTitlePlaceholder, IsCollection = regionType.Collection, Expanded = regionType.ListExpand, Icon = regionType.Icon, Display = regionType.Display.ToString().ToLower() } }; var regionListModel = ((IDictionary <string, object>)content.Regions)[regionType.Id]; if (!regionType.Collection) { var regionModel = (IRegionList)Activator.CreateInstance(typeof(RegionList <>).MakeGenericType(regionListModel.GetType())); regionModel.Add(regionListModel); regionListModel = regionModel; } foreach (var regionModel in (IEnumerable)regionListModel) { var regionItem = new Models.Content.RegionItemModel(); foreach (var fieldType in regionType.Fields) { var appFieldType = App.Fields.GetByType(fieldType.Type); var field = new Models.Content.FieldModel { Meta = new Models.Content.FieldMeta { Id = fieldType.Id, Name = fieldType.Title, Component = appFieldType.Component, Placeholder = fieldType.Placeholder, IsHalfWidth = fieldType.Options.HasFlag(FieldOption.HalfWidth), Description = fieldType.Description } }; if (typeof(SelectFieldBase).IsAssignableFrom(appFieldType.Type)) { foreach (var item in ((SelectFieldBase)Activator.CreateInstance(appFieldType.Type)).Items) { field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title); } } if (regionType.Fields.Count > 1) { field.Model = (IField)((IDictionary <string, object>)regionModel)[fieldType.Id]; if (regionType.ListTitleField == fieldType.Id) { regionItem.Title = field.Model.GetTitle(); field.Meta.NotifyChange = true; } } else { field.Model = (IField)regionModel; field.Meta.NotifyChange = true; regionItem.Title = field.Model.GetTitle(); } regionItem.Fields.Add(field); } if (string.IsNullOrWhiteSpace(regionItem.Title)) { regionItem.Title = "..."; } region.Items.Add(regionItem); } model.Regions.Add(region); } if (type.UseBlocks) { model.UseBlocks = true; foreach (var block in content.Blocks) { var blockType = App.Blocks.GetByType(block.Type); if (block is BlockGroup) { var group = new Models.Content.BlockGroupModel { Id = block.Id, Type = block.Type, Meta = new Models.Content.BlockMeta { Name = blockType.Name, Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower(), IsGroup = true, isCollapsed = config.ManagerDefaultCollapsedBlocks, ShowHeader = !config.ManagerDefaultCollapsedBlockGroupHeaders } }; group.Fields = ContentUtils.GetBlockFields(block); bool firstChild = true; foreach (var child in ((BlockGroup)block).Items) { blockType = App.Blocks.GetByType(child.Type); if (!blockType.IsGeneric) { // Regular block item model group.Items.Add(new Models.Content.BlockItemModel { IsActive = firstChild, Model = child, Meta = new Models.Content.BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower() } }); } else { // Generic block item model group.Items.Add(new Models.Content.BlockGenericModel { IsActive = firstChild, Model = ContentUtils.GetBlockFields(child), Type = child.Type, Meta = new Models.Content.BlockMeta { Name = blockType.Name, Title = child.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower() } }); } firstChild = false; } model.Blocks.Add(group); } else { if (!blockType.IsGeneric) { // Regular block item model model.Blocks.Add(new Models.Content.BlockItemModel { Model = block, Meta = new Models.Content.BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower(), isCollapsed = config.ManagerDefaultCollapsedBlocks } }); } else { // Generic block item model model.Blocks.Add(new Models.Content.BlockGenericModel { Model = ContentUtils.GetBlockFields(block), Type = block.Type, Meta = new Models.Content.BlockMeta { Name = blockType.Name, Title = block.GetTitle(), Icon = blockType.Icon, Component = blockType.Component, Width = blockType.Width.ToString().ToLower(), isCollapsed = config.ManagerDefaultCollapsedBlocks } }); } } } } // Custom editors foreach (var editor in type.CustomEditors) { model.Editors.Add(new Models.Content.EditorModel { Component = editor.Component, Icon = editor.Icon, Name = editor.Title }); } return(model); }
public EmailTemplateConverterTests() { fakeDynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); fakeDynamicContentItem = A.Dummy <DynamicContent>(); }
public void DynamicWidgets_VerifySelectedItemsFunctionalityWithNoLimit() { this.pageOperations = new PagesOperations(); string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name; string pageNamePrefix = testName + "DynamicPage"; string pageTitlePrefix = testName + "Dynamic Page"; string urlNamePrefix = testName + "dynamic-page"; int index = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index); string[] itemsNames = new string[25]; try { for (int i = 0; i < 25; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticleItem("Title" + i, "Title" + i + "Url"); itemsNames[i] = "Title" + i; } var dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SelectionMode = SelectionMode.SelectedItems; dynamicController.Model.DisplayMode = ListDisplayMode.All; dynamicController.Model.ItemsPerPage = 5; dynamicController.Model.LimitCount = 5; dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName; var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(DynamicContentController).FullName; mvcProxy.Settings = new ControllerSettings(dynamicController); mvcProxy.WidgetName = WidgetName; string[] selectedDynamicTitles = { "Title7", "Title15", "Title11", "Title3", "Title5", "Title8", "Title2", "Title16", "Title6" }; var selectedDynamicItems = new DynamicContent[9]; for (int i = 0; i < selectedDynamicTitles.Count(); i++) { selectedDynamicItems[i] = dynamicCollection.FirstOrDefault <DynamicContent>(n => n.UrlName == (selectedDynamicTitles[i] + "Url")); } //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]" dynamicController.Model.SerializedSelectedItemsIds = "[\"" + selectedDynamicItems[0].Id.ToString() + "\"," + "\"" + selectedDynamicItems[1].Id.ToString() + "\"," + "\"" + selectedDynamicItems[2].Id.ToString() + "\"," + "\"" + selectedDynamicItems[3].Id.ToString() + "\"," + "\"" + selectedDynamicItems[4].Id.ToString() + "\"," + "\"" + selectedDynamicItems[5].Id.ToString() + "\"," + "\"" + selectedDynamicItems[6].Id.ToString() + "\"," + "\"" + selectedDynamicItems[7].Id.ToString() + "\"," + "\"" + selectedDynamicItems[8].Id.ToString() + "\"]"; this.VerifyCorrectItemsOnPageWithNoLimitsOption(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index, url, selectedDynamicTitles); dynamicController.Model.SelectionMode = SelectionMode.AllItems; this.VerifyCorrectItemsOnPageWithNoLimitsOption(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index, url, itemsNames); } finally { ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); } }
public PreSearchFilterConverterTests() { dynamicContentExtensions = A.Fake <IDynamicContentExtensions>(); dummyDynamicContent = A.Dummy <DynamicContent>(); }
public void DynamicWidgets_VerifySelectedItemsFunctionalityWithSortDescending() { string sortExpession = "Title DESC"; string[] selectedDynamicTitles = { "Title2", "Title7", "Title5" }; string[] expectedDynamicTitles = { "Title7", "Title5", "Title2" }; try { for (int i = 0; i < 10; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticleItem("Title" + i, "Title" + i + "Url"); } var dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SelectionMode = SelectionMode.SelectedItems; dynamicController.Model.SortExpression = sortExpession; dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName; var selectedDynamicItems = new DynamicContent[3]; for (int i = 0; i < selectedDynamicTitles.Count(); i++) { selectedDynamicItems[i] = dynamicCollection.FirstOrDefault <DynamicContent>(n => n.UrlName == (selectedDynamicTitles[i] + "Url")); } //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]" dynamicController.Model.SerializedSelectedItemsIds = "[\"" + selectedDynamicItems[0].Id.ToString() + "\"," + "\"" + selectedDynamicItems[1].Id.ToString() + "\"," + "\"" + selectedDynamicItems[2].Id.ToString() + "\"]"; var modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: null, page: 1); var dynamicItems = modelItems.Items.ToList(); int itemsCount = dynamicItems.Count; for (int i = 0; i < itemsCount; i++) { Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(expectedDynamicTitles[i]), "The item with this title was not found!"); } dynamicController.Model.SelectionMode = SelectionMode.AllItems; modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: null, page: 1); dynamicItems = modelItems.Items.ToList(); int lastIndex = 9; for (int i = 0; i < 10; i++) { Assert.IsTrue(dynamicItems[i].Fields.Title.Equals(this.dynamicTitle + lastIndex), "The item with this title was not found!"); lastIndex--; } } finally { ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); } }
public void DynamicWidgets_VerifySelectedItemsFunctionalityWithUseLimit() { this.pageOperations = new PagesOperations(); string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name; string pageNamePrefix = testName + "DynamicPage"; string pageTitlePrefix = testName + "Dynamic Page"; string urlNamePrefix = testName + "dynamic-page"; int index = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index); try { for (int i = 0; i < 20; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticleItem("Title" + i, "Title" + i + "Url"); } var dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SelectionMode = SelectionMode.SelectedItems; dynamicController.Model.DisplayMode = ListDisplayMode.Limit; dynamicController.Model.ItemsPerPage = 5; dynamicController.Model.SortExpression = AsSetManuallySortingOption; var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(DynamicContentController).FullName; mvcProxy.Settings = new ControllerSettings(dynamicController); mvcProxy.WidgetName = WidgetName; string[] selectedDynamicTitles = { "Title7", "Title15", "Title11", "Title3", "Title5", "Title8", "Title2", "Title16", "Title6" }; var selectedDynamicItems = new DynamicContent[9]; for (int i = 0; i < selectedDynamicTitles.Count(); i++) { selectedDynamicItems[i] = dynamicCollection.FirstOrDefault<DynamicContent>(n => n.UrlName == (selectedDynamicTitles[i] + "Url")); } //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]" dynamicController.Model.SerializedSelectedItemsIds = "[\"" + selectedDynamicItems[0].Id.ToString() + "\"," + "\"" + selectedDynamicItems[1].Id.ToString() + "\"," + "\"" + selectedDynamicItems[2].Id.ToString() + "\"," + "\"" + selectedDynamicItems[3].Id.ToString() + "\"," + "\"" + selectedDynamicItems[4].Id.ToString() + "\"," + "\"" + selectedDynamicItems[5].Id.ToString() + "\"," + "\"" + selectedDynamicItems[6].Id.ToString() + "\"," + "\"" + selectedDynamicItems[7].Id.ToString() + "\"," + "\"" + selectedDynamicItems[8].Id.ToString() + "\"]"; this.VerifyCorrectItemsOnPageWithUseLimitsOption(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index, url, selectedDynamicTitles); } finally { this.pageOperations.DeletePages(); ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); } }
/// <summary> /// Gets the related articles /// </summary> /// <param name="obj">The Dynamic Content.</param> /// <returns>IList of NewsItem</returns> public static IList<NewsItem> GetRelatedArticles(DynamicContent obj) { IList<NewsItem> relatedArticles = new List<NewsItem>(); var relatedDataItems = obj.GetRelatedParentItems(typeof(NewsItem).FullName); foreach (var item in relatedDataItems) { NewsManager newsManager = NewsManager.GetManager(); var newsItem = newsManager.GetNewsItem(item.Id); if (newsItem != null) relatedArticles.Add(newsItem); } return relatedArticles; }
public void EditPressArticleTitle(DynamicContent pressArticleItem, string newTitle) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = string.Empty; DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); pressArticleItem.SetValue("Title", newTitle); dynamicModuleManager.Lifecycle.Publish(pressArticleItem); // You need to call SaveChanges() in order for the items to be actually persisted to data store dynamicModuleManager.SaveChanges(); }
/// <summary> /// Gets the author view model. /// </summary> /// <param name="obj">The object.</param> /// <param name="currentNewsItem">The current news item.</param> /// <returns>Author View Moddel</returns> public static AuthorViewModel GetAuthorViewModel(DynamicContent obj, NewsItem currentNewsItem = null) { return new AuthorViewModel { Id = obj.Id, Author = obj, ItemDefaultUrl = obj.ItemDefaultUrl, Name = obj.GetString("Name"), JobTitle = obj.GetString("JobTitle"), Bio = obj.GetString("Bio"), Avatar = new ImageViewModel() { ImageUrl = UrlHelper.GetRelatedMediaUrl(obj, "Avatar") }, ProviderName = obj.ProviderName, RelatedArticles = AuthorViewModel.GetRelatedArticles(obj), DetailedArticle = (currentNewsItem != null) ? currentNewsItem : null }; }
private void AddCustomTaxonomy(IEnumerable<string> taxonNames, string taxonomyName, DynamicContent pressArticleItem) { TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); foreach (var taxonName in taxonNames) { var taxon = taxonomyManager.GetTaxa<FlatTaxon>().Where(t => t.Title == taxonName).FirstOrDefault(); if (taxon != null) { pressArticleItem.Organizer.AddTaxa(taxonomyName, taxon.Id); } } }
private DataModel Typify(DynamicContent dynamicItem) { return new DataModel(dynamicItem); }
/// <summary> /// Transform content to a edit model. /// </summary> /// <param name="content">The dynamic content object</param> /// <returns>Edit model</returns> private ContentEditModel Transform(DynamicContent content) { var config = new Config(_api); var type = App.ContentTypes.GetById(content.TypeId); var model = new ContentEditModel { Id = content.Id, TypeId = content.TypeId, PrimaryImage = content.PrimaryImage, Title = content.Title, UsePrimaryImage = type.UsePrimaryImage, UseExcerpt = type.UseExcerpt, UseHtmlExcerpt = config.HtmlExcerpt }; foreach (var regionType in type.Regions) { var region = new Models.Content.RegionModel { Meta = new Models.Content.RegionMeta { Id = regionType.Id, Name = regionType.Title, Description = regionType.Description, Placeholder = regionType.ListTitlePlaceholder, IsCollection = regionType.Collection, Expanded = regionType.ListExpand, Icon = regionType.Icon, Display = regionType.Display.ToString().ToLower() } }; var regionListModel = ((IDictionary <string, object>)content.Regions)[regionType.Id]; if (!regionType.Collection) { var regionModel = (IRegionList)Activator.CreateInstance(typeof(RegionList <>).MakeGenericType(regionListModel.GetType())); regionModel.Add(regionListModel); regionListModel = regionModel; } foreach (var regionModel in (IEnumerable)regionListModel) { var regionItem = new Models.Content.RegionItemModel(); foreach (var fieldType in regionType.Fields) { var appFieldType = App.Fields.GetByType(fieldType.Type); var field = new Models.Content.FieldModel { Meta = new Models.Content.FieldMeta { Id = fieldType.Id, Name = fieldType.Title, Component = appFieldType.Component, Placeholder = fieldType.Placeholder, IsHalfWidth = fieldType.Options.HasFlag(FieldOption.HalfWidth), Description = fieldType.Description } }; if (typeof(SelectFieldBase).IsAssignableFrom(appFieldType.Type)) { foreach (var item in ((SelectFieldBase)Activator.CreateInstance(appFieldType.Type)).Items) { field.Meta.Options.Add(Convert.ToInt32(item.Value), item.Title); } } if (regionType.Fields.Count > 1) { field.Model = (IField)((IDictionary <string, object>)regionModel)[fieldType.Id]; if (regionType.ListTitleField == fieldType.Id) { regionItem.Title = field.Model.GetTitle(); field.Meta.NotifyChange = true; } } else { field.Model = (IField)regionModel; field.Meta.NotifyChange = true; regionItem.Title = field.Model.GetTitle(); } regionItem.Fields.Add(field); } if (string.IsNullOrWhiteSpace(regionItem.Title)) { regionItem.Title = "..."; } region.Items.Add(regionItem); } model.Regions.Add(region); } // Custom editors foreach (var editor in type.CustomEditors) { model.Editors.Add(new Models.Content.EditorModel { Component = editor.Component, Icon = editor.Icon, Name = editor.Title }); } return(model); }
public DataModel(DynamicContent dynamicItem) { this.dynamicItem = dynamicItem; }
public DataModel(DynamicContent dynamicItem) { this.dynamicItem = dynamicItem; }
private void AddCustomTaxonomy(IEnumerable <string> taxonNames, string taxonomyName, DynamicContent pressArticleItem, bool isHierarchicalTaxonomy = false) { TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); if (!isHierarchicalTaxonomy) { foreach (var taxonName in taxonNames) { var taxon = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Title == taxonName).FirstOrDefault(); if (taxon != null) { pressArticleItem.Organizer.AddTaxa(taxonomyName, taxon.Id); } } } else { foreach (var taxonName in taxonNames) { var taxon = taxonomyManager.GetTaxa <HierarchicalTaxon>().Where(t => t.Title == taxonName).FirstOrDefault(); if (taxon != null) { pressArticleItem.Organizer.AddTaxa(taxonomyName, taxon.Id); } } } }
/// <summary> /// Validates a DynamicContent item has a field defined, thx Stacey Schlenker for the update\testing /// </summary> /// <param name="dataItem"></param> /// <param name="field"></param> /// <returns></returns> public static bool HasValue(this DynamicContent dataItem, string field) { return(App.WorkWith().DynamicData().Type(dataItem.GetType()).Get().Fields.Any(f => f.FieldName == field)); }
partial void UpdateDynamicContent(DynamicContent instance);
protected Guid SaveImageToSitefinity(string Url, DynamicContent syncedVideoItem, string title) { try { string extension; var imageToSave = ReturnImageStreamFromUrl(Url, out extension); LibrariesManager librariesManager = LibrariesManager.GetManager(); librariesManager.Provider.SuppressSecurityChecks = true; //The album post is created as master. The masterImageId is assigned to the master version. Image image = librariesManager.CreateImage(); //Set the parent album. Album album = librariesManager.GetAlbums().Where(i => i.Title == config.ThumbLibName).SingleOrDefault(); if (album == null) { CreateNewAlbum(out album, config.ThumbLibName, librariesManager); } image.Parent = album; //Set the properties of the image. image.Title = title; image.DateCreated = DateTime.UtcNow; image.PublicationDate = DateTime.UtcNow; image.LastModified = DateTime.UtcNow; int intAppend = 0; Image imgToTest; string testName; do // Test url-name to verify doesnt exist { intAppend++; testName = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-") + "-" + intAppend; imgToTest = librariesManager.GetImages().Where(i => i.UrlName == testName).FirstOrDefault(); } while (imgToTest != null); image.UrlName = testName; //Upload the image file. librariesManager.Upload(image, imageToSave, extension); image.SetWorkflowStatus(librariesManager.Provider.ApplicationName, "Published"); librariesManager.Lifecycle.Publish(image); librariesManager.SaveChanges(); librariesManager.Provider.SuppressSecurityChecks = false; return image.Id; } catch (Exception e) { Logger.Writer.Write("The WebVideoSync process failed on video id: " + syncedVideoItem.GetValue("YouTubeVidId") + ". The title of the video that failed was: \"" + title + "\". Stack trace below:\n"); Logger.Writer.Write(e.StackTrace); return Guid.Empty; } }
public void createUpdateVideo(DynamicContent sitefinityVideo, goog.Video vid) { DynamicContent syncedVideoItem; // Create new video if (sitefinityVideo == null) { syncedVideoItem = dynamicModuleManager.CreateDataItem(syncedVideoType); syncedVideoItem.SetString("UrlName", Regex.Replace(vid.VideoId.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-")); //syncedVideoItem.SetValue("Owner", user.Id); } else // Check-out existing video { syncedVideoItem = dynamicModuleManager.Lifecycle.CheckOut(sitefinityVideo) as DynamicContent; } // Add/Update fields syncedVideoItem.SetValue("PublicationDate", vid.YouTubeEntry.Published); syncedVideoItem.SetValue("YouTubeVidId", vid.VideoId); syncedVideoItem.SetValue("Title", vid.Title); syncedVideoItem.SetValue("Duration", vid.Media.Duration.Seconds); // Delete existing thumbnail if it already exists. if (syncedVideoItem.GetValue<ContentLink[]>("Thumbnail") != null) { Guid ThumbID = syncedVideoItem.GetValue<ContentLink[]>("Thumbnail")[0].ChildItemId; LibrariesManager librariesManager = LibrariesManager.GetManager(); Image thumbToDelete = librariesManager.GetImages().Where(i => i.Id == ThumbID).FirstOrDefault(); if (thumbToDelete != null) { librariesManager.DeleteImage(thumbToDelete); librariesManager.SaveChanges(); } } // Create and save Thumnail if (vid.Media.Thumbnails != null && vid.Media.Thumbnails.Count > 0) { var thumb = vid.Media.Thumbnails.OrderBy(k => k.Width).Reverse().FirstOrDefault(); Guid imgId = SaveImageToSitefinity(thumb.Url, syncedVideoItem, vid.Title); ContentLinksManager manager = ContentLinksManager.GetManager(); // Make sure to test when there are no content links in the Thumbnail field. if (syncedVideoItem.GetValue<ContentLink[]>("Thumbnail") != null) { syncedVideoItem.ClearImages("Thumbnail"); syncedVideoItem.SetValue("Thumbnail", null); } if (imgId != Guid.Empty) syncedVideoItem.AddImage("Thumbnail", imgId); } // Save new video if (sitefinityVideo == null) { syncedVideoItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); ILifecycleDataItem publishedSyncedVideoItem = dynamicModuleManager.Lifecycle.Publish(syncedVideoItem); syncedVideoItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.SaveChanges(); } else // Check-in pre-existing video { ILifecycleDataItem checkInSyncedVideoItem = dynamicModuleManager.Lifecycle.CheckIn(syncedVideoItem); dynamicModuleManager.Lifecycle.Publish(checkInSyncedVideoItem); dynamicModuleManager.SaveChanges(); } }
public static int GetIntValueOrDefault(DynamicContent item, string property, int defaultValue = 0) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToInt32(propertyValue); }
/// <summary> /// Gets the issue view model. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public static IssueViewModel GetIssue(DynamicContent item) { IssueViewModel issue = new IssueViewModel(); issue.Title = item.GetString("Title"); issue.Id = item.Id; issue.UrlName = item.ItemDefaultUrl; issue.Description = item.GetString("Description"); issue.Number = item.GetString("IssueNumber"); issue.Cover = ImagesHelper.GetRelatedImage(item, "IssueCover"); issue.ProviderName = item.ProviderName; issue.PrintedVersion = DocumentsHelper.GetRelatedDocument(item, "IssueDocument"); issue.Articles = item.GetRelatedItems<NewsItem>("Articles"); issue.FeaturedArticle = item.GetRelatedItems<NewsItem>("FeaturedArticle"); return issue; }