public override PhotoResourceDto Persist(PhotoResourceDto photoResourceDto) { Gallery gallery = _galleryDao.FindSingle(new GalleryFilterDto() { OwnerId = photoResourceDto.UserDefinableOwnerId }); bool automaticCoverPhotoSet = false; if (gallery == null) { gallery = CreateAndPersistEmptyProfileGallery(photoResourceDto.UserDefinableOwnerId); automaticCoverPhotoSet = true; } photoResourceDto.UserDefinableId = gallery.Id; PhotoThumbnailInfo photoThumbnailInfo = PhotoThumbnailInfoProvider.GetDefault(photoResourceDto.OwnerType); photoResourceDto.Path = string.Format(photoThumbnailInfo.Path, photoResourceDto.UserDefinableOwnerId, photoResourceDto.UserDefinableId); photoResourceDto = base.Persist(photoResourceDto); if (automaticCoverPhotoSet) { gallery.CoverPhotoId = photoResourceDto.Id; _genericDao.Persist <Gallery>(gallery); } return(photoResourceDto); }
private IList <ValidationResult> IsMaximumPhotoLimitReached(PhotoResourceDto photoResourceDto) { IList <ValidationResult> validationResults = new List <ValidationResult>(); int maximumPhotoLimit = PhotoThumbnailInfoProvider.GetDefault(photoResourceDto.OwnerType).MaximumPhotos; int currentPhotoCount = _genericDao.Count <Resource>(x => x.UserDefinableId == photoResourceDto.UserDefinableId); if (currentPhotoCount >= maximumPhotoLimit) { validationResults.Add(new ValidationResult(MessageKeyConstants.VALIDATION_MAXIMUM_RESOURCES_REACHED_MESSAGE, maximumPhotoLimit)); } return(validationResults); }
private IList <ValidationResult> IsImage(PhotoResourceDto photoResourceDto) { IList <ValidationResult> validationResults = new List <ValidationResult>(); try { using (Image image = Image.FromStream(photoResourceDto.Stream, false, false)) { PhotoThumbnailInfo photoThumbnailInfo = PhotoThumbnailInfoProvider.GetDefault(photoResourceDto.OwnerType); if (photoThumbnailInfo.MinimumHeight < image.Height || photoThumbnailInfo.MinimumWidth < image.Width) { validationResults.Add(new ValidationResult(MessageKeyConstants.VALIDATION_IMAGE_MINIMUM_SIZE_MESSAGE, image.Width, image.Height, photoThumbnailInfo.MinimumWidth, photoThumbnailInfo.MinimumHeight)); } return(validationResults); } } catch { validationResults.Add(new ValidationResult(MessageKeyConstants.VALIDATION_FILE_IS_IN_WRONG_FORMAT_MESSAGE, "Image")); } return(validationResults); }
public GalleryDto(Type type) { PhotoThumbnailInfo = PhotoThumbnailInfoProvider.GetDefault(type); }
private Size GetMaximumPhotoSize(PhotoResourceDto photoResourceDto) { PhotoThumbnailInfo photoThumbnailInfo = PhotoThumbnailInfoProvider.GetDefault(photoResourceDto.OwnerType); return(new Size(photoThumbnailInfo.MinimumWidth, photoThumbnailInfo.MinimumHeight)); }