private ImageGallerySettingsRecord CreateImageGallerySettings(string imageGalleryMediaPath, int thumbnailHeight, int thumbnailWidth,
            bool keepAspectRatio)
        {
            ImageGallerySettingsRecord imageGallerySettings = new ImageGallerySettingsRecord
                                                              {
                                                                  ImageGalleryName = GetName(imageGalleryMediaPath),
                                                                  ThumbnailHeight = thumbnailHeight,
                                                                  ThumbnailWidth = thumbnailWidth,
                                                                  KeepAspectRatio = keepAspectRatio
                                                              };
            _repository.Create(imageGallerySettings);

            return imageGallerySettings;
        }
 private ImageGalleryImageSettingsRecord GetImageSettings(ImageGallerySettingsRecord imageGallerySettings, string imageName)
 {
     if (imageGallerySettings == null || imageGallerySettings.ImageSettings == null)
         return null;
     return imageGallerySettings.ImageSettings.SingleOrDefault(o => o.Name == imageName);
 }
        private ImageGalleryImage CreateImageFromMediaFile(MediaFile mediaFile, ImageGallerySettingsRecord imageGallerySettings)
        {
            if (imageGallerySettings == null) {
                throw new ArgumentNullException("imageGallerySettings");
            }

            var imageSettings = GetImageSettings(imageGallerySettings, mediaFile.Name);
            bool isValidThumbnailSize = imageGallerySettings.ThumbnailWidth > 0 &&
                                        imageGallerySettings.ThumbnailHeight > 0;
            Thumbnail thumbnail = null;

            if (isValidThumbnailSize) {
                thumbnail = _thumbnailService.GetThumbnail( _storageProvider.Combine(mediaFile.FolderName, mediaFile.Name),
                                                              imageGallerySettings.ThumbnailWidth,
                                                              imageGallerySettings.ThumbnailHeight,
                                                              imageGallerySettings.KeepAspectRatio);
            }

            return new ImageGalleryImage
                   {
                       PublicUrl = _mediaService.GetPublicUrl(Path.Combine(mediaFile.FolderName, mediaFile.Name)),
                       Name = mediaFile.Name,
                       Size = mediaFile.Size,
                       User = mediaFile.User,
                       LastUpdated = mediaFile.LastUpdated,
                       Caption = imageSettings == null ? string.Empty : imageSettings.Caption,
                       Thumbnail = thumbnail,
                       Title = imageSettings == null ? null : imageSettings.Title,
                       Position = imageSettings == null ? 0 : imageSettings.Position
                   };
        }