public LightboxPreviewModel GetGalleryPreviewModel(IEnumerable <int> mediaIds, IPresetStrategy strategy) { var medias = Umbraco.Web.Composing.Current.UmbracoHelper.Media(mediaIds); var mediasList = medias.ToList(); var galleryViewModelList = mediasList.Select(MapToMedia).ToList(); TransformPreviewImage(galleryViewModelList, strategy); var mediasViewModel = FindMedias(galleryViewModelList); var galleryPreviewModel = new LightboxPreviewModel { Medias = mediasViewModel.Map <IEnumerable <LightboxGalleryItemPreviewModel> >(), OtherFiles = galleryViewModelList.Except(mediasViewModel) .Map <IEnumerable <LightboxGalleryItemPreviewModel> >() }; galleryPreviewModel.Medias = galleryPreviewModel.Medias .Select(MapAsHidden()) .ToList(); galleryPreviewModel.HiddenImagesCount = galleryPreviewModel.Medias.Count(i => i.IsHidden); galleryPreviewModel.FilesToDisplay = strategy.MediaFilesToDisplay; var count = mediasViewModel.Count; if (count > 2) { galleryPreviewModel.AdditionalImages = Math.Abs(strategy.MediaFilesToDisplay - count); } return(galleryPreviewModel); }
private void TransformPreviewImage(List <LightboxGalleryItemViewModel> galleryItems, IPresetStrategy strategy) { var imageItems = galleryItems.FindAll(m => m.Type is MediaTypeEnum.Image || m.Type is MediaTypeEnum.Video); if (imageItems.Count == 1) { var item = imageItems[0]; item.PreviewUrl = _imageHelper.GetImageWithResize(IsVideo(item.Type) ? item.PreviewUrl : item.Url, strategy.PreviewPreset); return; } foreach (var item in imageItems) { item.PreviewUrl = imageItems.Count < 3 ? _imageHelper.GetImageWithResize(IsVideo(item.Type) ? item.PreviewUrl : item.Url, strategy.PreviewTwoPreset) : _imageHelper.GetImageWithResize(IsVideo(item.Type) ? item.PreviewUrl : item.Url, strategy.ThumbnailPreset); } }