protected virtual ConferenceModel PopulateModel(DynamicContent conference)
        {
            var images       = conference.GetRelatedItems <Image>("Images");
            var imagesModels = new List <ImageModel>();

            foreach (var img in images)
            {
                var model = new ImageModel();
                model.Title           = img.Title;
                model.AlternativeText = img.AlternativeText;
                model.ThumbnailUrl    = img.ResolveThumbnailUrl();
                imagesModels.Add(model);
            }

            var sessions       = conference.GetRelatedItems <DynamicContent>("Sessions");
            var sessionsModels = new List <SessionModel>();

            foreach (var session in sessions)
            {
                var model = new SessionModel();
                model.Title     = session.GetValue <Lstring>("Title");
                model.Duration  = session.GetValue <decimal?>("Duration");
                model.DetailUrl = session.GetDefaultUrl();
                sessionsModels.Add(model);
            }

            var conferenceModel = new ConferenceModel();

            conferenceModel.Images   = imagesModels;
            conferenceModel.Sessions = sessionsModels;

            return(conferenceModel);
        }
Beispiel #2
0
 public IQueryable <DynamicContent> GetRelatedItems(DynamicContent contentItem, string fieldName, int maximumItemsToReturn = Constants.DefaultMaxRelatedItems)
 {
     return((contentItem.ApprovalWorkflowState == Constants.WorkflowStatusDraft && contentItem.GetType().Name == Constants.JobProfile)
         ? contentItem?
            .GetRelatedItems <DynamicContent>(fieldName).Where(d => d.Status == ContentLifecycleStatus.Master).Take(maximumItemsToReturn)
         : contentItem?
            .GetRelatedItems <DynamicContent>(fieldName)
            .Where(d => d.Status == ContentLifecycleStatus.Live && d.Visible)
            .Take(maximumItemsToReturn));
 }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
 public IQueryable <DynamicContent> GetRelatedItems(DynamicContent contentItem, string fieldName, int maximumItemsToReturn = Constants.DefaultMaxRelatedItems)
 {
     return(contentItem?
            .GetRelatedItems <DynamicContent>(fieldName)
            .Where(d => d.Status == ContentLifecycleStatus.Live && d.Visible)
            .Take(maximumItemsToReturn));
 }
Beispiel #6
0
 public IEnumerable <DynamicContent> GetRelatedSearchItems(DynamicContent contentItem, string fieldName, int maximumItemsToReturn = Constants.DefaultMaxRelatedItems)
 {
     return(contentItem?
            .GetRelatedItems <DynamicContent>(fieldName)
            .Where(d => d.ApprovalWorkflowState == PublishedWorkFlowStatus && (d.Status == ContentLifecycleStatus.Live || d.Status == ContentLifecycleStatus.Master))
            .Take(maximumItemsToReturn).ToList());
 }
Beispiel #7
0
        public House(DynamicContent house)
        {
            this.Id      = house.OriginalContentId;
            this.Title   = house.GetString("Title");
            this.LogoUrl = house.GetRelatedItems <Image>("Logo")?.FirstOrDefault()?.MediaUrl;

            this.CacheDate = DateTime.Now;
        }
Beispiel #8
0
        /// <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);
        }
Beispiel #9
0
 private OfficeViewModel ToViewModel(DynamicContent office) =>
 new OfficeViewModel
 {
     Id      = office.Id,
     Title   = office.GetString("Title").Value,
     Info    = office.GetString("Info").Value,
     Picture = this.GetImageViewModel(office.GetRelatedItems <Image>("Picture").ToList())
 };
        private static object GetRelatedContent(DynamicContent content, PropertyInfo property, string includeString)
        {
            var relatedContent = content.GetRelatedItems(property.PropertyType.Name)?.Cast <DynamicContent>()?.FirstOrDefault();

            // We can't call a generic with a runtime type, so we need to use reflection.
            var mapMethod = typeof(DynamicContentExtensions).GetMethod(nameof(DynamicContentExtensions.MapTo), new [] { typeof(DynamicContent), typeof(string) });
            var generic   = mapMethod.MakeGenericMethod(property.PropertyType);

            // Map the related content in case the related value ALSO needs to grab related content.
            var relatedContentMapped = generic.Invoke(null, new object[] { relatedContent, includeString });

            return(relatedContentMapped);
        }
        /// <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;
        }
Beispiel #12
0
        private PetModel CreateModel(DynamicContent dynItem)
        {
            PetModel model = new PetModel();

            model.Name = dynItem.GetValue("Name").ToString();

            string imgUrl     = "";
            Image  imageField = dynItem.GetRelatedItems <Image>("Image").FirstOrDefault();

            if (imageField != null)
            {
                imgUrl = imageField.Url;
            }
            model.ImageUrl = imgUrl;
            model.Id       = dynItem.Id;
            return(model);
        }
Beispiel #13
0
        /// <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);
        }
        /// <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;
        }
        /// <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;
        }
Beispiel #17
0
        /// <summary>
        /// Updates the OG item model.
        /// </summary>
        /// <param name="itemsType">Type of the item</param>
        /// <param name="ogModel">The open graph model</param>
        /// <param name="pageUrl">The url</param>
        /// <returns> true or false</returns>
        private bool GetDataItemByType(Type itemsType, OpengraphModuleConfig ogModel, string pageUrl)
        {
            switch (itemsType.FullName)
            {
            //Default type
            case "Telerik.Sitefinity.News.Model.NewsItem":
                NewsManager newsManager = NewsManager.GetManager();
                List <Telerik.Sitefinity.News.Model.NewsItem> items = newsManager.GetNewsItems().Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true).ToList();
                Telerik.Sitefinity.News.Model.NewsItem        item  = items.FirstOrDefault(newsItem => newsItem.ItemDefaultUrl == pageUrl);

                if (item == null)
                {
                    return(false);
                }

                //Default
                openGraphModel.ogTitle = item.Title.ToString();
                //Given property
                if (item.DoesFieldExist(ogModel.TitlePropertyName))
                {
                    if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString()))
                    {
                        openGraphModel.ogTitle = item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString();
                    }
                }

                //Default OG prop
                if (item.DoesFieldExist("OpenGraphTitle"))
                {
                    if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphTitle").ToString()))
                    {
                        openGraphModel.ogTitle = item.GetValue <Lstring>("OpenGraphTitle").ToString();
                    }
                }
                //OG prop
                if (item.DoesFieldExist("LgszOpenGraphTitle"))
                {
                    if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphTitle").ToString()))
                    {
                        openGraphModel.ogTitle = item.GetValue <Lstring>("LgszOpenGraphTitle").ToString();
                    }
                }



                //Default
                openGraphModel.ogDescription = item.Summary != null?item.Summary.ToString() : openGraphDefaultDescription;

                //Given property
                if (item.DoesFieldExist(ogModel.DescriptionPropertyName))
                {
                    if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString()))
                    {
                        openGraphModel.ogDescription = item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString();
                    }
                }
                //Default OG prop
                if (item.DoesFieldExist("OpenGraphDescription"))
                {
                    if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphDescription").ToString()))
                    {
                        openGraphModel.ogDescription = item.GetValue <Lstring>("OpenGraphDescription").ToString();
                    }
                }
                //OG prop
                if (item.DoesFieldExist("LgszOpenGraphDescription"))
                {
                    if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphDescription").ToString()))
                    {
                        openGraphModel.ogDescription = item.GetValue <Lstring>("LgszOpenGraphDescription").ToString();
                    }
                }



                Telerik.Sitefinity.Libraries.Model.Image image = null;
                IDataItem newsImage = null;

                openGraphModel.ogImage = openGraphDefaultImage;
                if (item.DoesFieldExist(ogModel.ImagePropertyName))
                {
                    if (item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null)
                    {
                        newsImage = item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault();
                    }
                }

                if (item.DoesFieldExist("OpenGraphImage"))
                {
                    if (item.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null)
                    {
                        newsImage = item.GetRelatedItems("OpenGraphImage").FirstOrDefault();
                    }
                }

                if (item.DoesFieldExist("LgszOpenGraphImage"))
                {
                    if (item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null)
                    {
                        newsImage = item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault();
                    }
                }

                if (newsImage != null)
                {
                    image = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == newsImage.Id);
                }
                if (image != null)
                {
                    openGraphModel.ogImage = image.Url;
                }

                return(true);

            default:
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();

                try
                {
                    string         redirectUrl;
                    DynamicContent currentDynamicItem = dynamicModuleManager.Provider.GetItemFromUrl(itemsType, pageUrl, true, out redirectUrl) as DynamicContent;

                    if (currentDynamicItem == null)
                    {
                        return(false);
                    }


                    //Given property
                    openGraphModel.ogTitle = openGraphDefaultTitle;

                    if (!String.IsNullOrEmpty(ogModel.TitlePropertyName))
                    {
                        openGraphModel.ogTitle = ParseFieldTags(ogModel.TitlePropertyName, currentDynamicItem);
                    }
                    //Default OG prop
                    if (currentDynamicItem.DoesFieldExist("OpenGraphTitle"))
                    {
                        if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString()))
                        {
                            openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString();
                        }
                    }
                    //OG prop
                    if (currentDynamicItem.DoesFieldExist("LgszOpenGraphTitle"))
                    {
                        if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString()))
                        {
                            openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString();
                        }
                    }


                    //Default
                    openGraphModel.ogDescription = openGraphDefaultDescription;

                    if (!String.IsNullOrEmpty(ogModel.DescriptionPropertyName))
                    {
                        openGraphModel.ogDescription = ParseFieldTags(ogModel.DescriptionPropertyName, currentDynamicItem);
                    }

                    //Default OG prop
                    if (currentDynamicItem.DoesFieldExist("OpenGraphDescription"))
                    {
                        if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString()))
                        {
                            openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString();
                        }
                    }
                    //OG prop
                    if (currentDynamicItem.DoesFieldExist("LgszOpenGraphDescription"))
                    {
                        if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString()))
                        {
                            openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString();
                        }
                    }



                    Telerik.Sitefinity.Libraries.Model.Image img = null;
                    IDataItem dynamicContentImage = null;

                    openGraphModel.ogImage = openGraphDefaultImage;
                    if (currentDynamicItem.DoesFieldExist(ogModel.ImagePropertyName))
                    {
                        if (currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null)
                        {
                            dynamicContentImage = currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault();
                        }
                    }

                    if (currentDynamicItem.DoesFieldExist("OpenGraphImage"))
                    {
                        if (currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null)
                        {
                            dynamicContentImage = currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault();
                        }
                    }

                    if (currentDynamicItem.DoesFieldExist("LgszOpenGraphImage"))
                    {
                        if (currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null)
                        {
                            dynamicContentImage = currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault();
                        }
                    }

                    if (dynamicContentImage != null)
                    {
                        img = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == dynamicContentImage.Id);
                    }
                    if (img != null)
                    {
                        openGraphModel.ogImage = img.Url;
                    }


                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
        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;
        }