Beispiel #1
0
 public MediaLibraryFileProfile()
 {
     CreateMap <MediaFileInfo, MediaLibraryFileDto>()
     .ForMember(dst => dst.Title, opt => opt.MapFrom(src => src.FileTitle))
     .ForMember(dst => dst.Extension, opt => opt.MapFrom(src => src.FileExtension))
     .ForMember(dst => dst.DirectUrl, opt => opt.MapFrom(src => MediaLibraryHelper.GetDirectUrl(src)))
     .ForMember(dst => dst.PermanentUrl, opt => opt.MapFrom(src => MediaLibraryHelper.GetPermanentUrl(src)));
 }
Beispiel #2
0
        public ActionResult Index()
        {
            var properties = GetProperties();

            if (properties.MediaLibraryItemGuid == default)
            {
                return(PartialView("Widgets/_MediaSelectionWidget",
                                   new MediaSelectionWidgetViewModel
                {
                    MaxSideSize = properties.MaxSideSize,
                    MediaLibraryItemGuid = properties.MediaLibraryItemGuid,
                    PermanentUrl = "",
                    Title = "",
                    HostUrl = cmsRequestContext.CmsHost
                }));
            }

            var mediaFileInfo = mediaFileQuery
                                .GetMediaFile(
                properties.MediaLibraryItemGuid,
                cmsRequestContext.SiteName);

            var viewModel = new MediaSelectionWidgetViewModel
            {
                MaxSideSize = properties.MaxSideSize,
                HostUrl     = cmsRequestContext.CmsHost,
            };

            if (mediaFileInfo is null)
            {
                viewModel.Title                = "";
                viewModel.PermanentUrl         = "";
                viewModel.MediaLibraryItemGuid = default;
            }
            else
            {
                viewModel.Title = mediaFileInfo.FileTitle;

                viewModel.PermanentUrl = MediaLibraryHelper
                                         .GetPermanentUrl(mediaFileInfo)
                                         .TrimStart('~');

                viewModel.MediaLibraryItemGuid = properties.MediaLibraryItemGuid;
            }

            return(PartialView("Widgets/_MediaSelectionWidget", viewModel));
        }
        public IEnumerable <MediaLibraryFileDto> GetMediaLibraryFiles(string folder, string sitename, params string[] extensions)
        {
            // Gets an instance of the media library for the current site
            var mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(folder, sitename);

            // Gets a collection of media files and their extensions from the media library
            return(MediaFileInfoProvider.GetMediaFiles()
                   .WhereEquals("FileLibraryID", mediaLibrary.LibraryID)
                   .WhereIn("FileExtension", extensions)
                   .ToList()
                   .Select(m => new MediaLibraryFileDto()
            {
                Title = m.FileTitle,
                Extension = m.FileExtension,
                DirectUrl = MediaLibraryHelper.GetDirectUrl(m),
                PermanentUrl = MediaLibraryHelper.GetPermanentUrl(m)
            }));
        }
Beispiel #4
0
        //DocSection:GetMediaFiles
        /// <summary>
        /// Retrieves media files with the .jpg extension from the 'SampleMediaLibrary'.
        /// </summary>
        public ActionResult ShowMediaFiles()
        {
            // Gets an instance of the 'SampleMediaLibrary' media library for the current site
            MediaLibraryInfo mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("SampleMediaLibrary", SiteContext.CurrentSiteName);

            // Gets a collection of media files with the .jpg extension from the media library
            IEnumerable <MediaFileInfo> mediaLibraryFiles = MediaFileInfoProvider.GetMediaFiles()
                                                            .WhereEquals("FileLibraryID", mediaLibrary.LibraryID)
                                                            .WhereEquals("FileExtension", ".jpg");

            // Prepares a collection of view models containing required data of the media files
            IEnumerable <MediaFileViewModel> model = mediaLibraryFiles.Select(
                mediaFile => new MediaFileViewModel
            {
                FileTitle    = mediaFile.FileTitle,
                DirectUrl    = MediaLibraryHelper.GetDirectUrl(mediaFile),
                PermanentUrl = MediaLibraryHelper.GetPermanentUrl(mediaFile)
            }
                );

            // Passes the model to the view
            return(View(model));
        }