Example #1
0
        public LinkPreview MapPreview(LinkPreviewEntity entity)
        {
            var result = new LinkPreview
            {
                Id          = entity.Id,
                Uri         = new UriBuilder(entity.Uri).Uri,
                Title       = entity.Title,
                Description = GetLongest(entity.OgDescription, entity.Description)
            };

            if (entity.MediaId.HasValue)
            {
                var media = _umbracoHelper.TypedMedia(entity.MediaId);
                result.ImageUri = media != null ? new Uri(media.Url, UriKind.Relative) : null;
            }
            else
            {
                result.ImageUri   = entity.ImageId.HasValue ? _linkPreviewUriProvider.GetImageUri(entity.ImageId.Value) : null;
                result.FaviconUri = entity.FaviconId.HasValue ? _linkPreviewUriProvider.GetImageUri(entity.FaviconId.Value) : null;
            }

            if (result.ImageUri == null)
            {
                result.ImageUri = new Uri(defaultPreviewImagePath, UriKind.Relative);
            }
            return(result);
        }
        public LinkPreview MapPreview(LinkPreviewEntity entity)
        {
            var result = new LinkPreview
            {
                Id          = entity.Id,
                Uri         = new UriBuilder(entity.Uri).Uri,
                Title       = entity.Title,
                Description = GetLongest(entity.OgDescription, entity.Description),
                ImageUri    = entity.ImageId.HasValue ? _linkPreviewUriProvider.GetImageUri(entity.ImageId.Value) : null,
                FaviconUri  = entity.FaviconId.HasValue ? _linkPreviewUriProvider.GetImageUri(entity.FaviconId.Value) : null
            };

            return(result);
        }