Пример #1
0
        /// <summary>
        /// 转换为相册实体
        /// </summary>
        /// <returns></returns>
        public Album AsAlbum()
        {
            Album        album        = null;
            IUser        currentUser  = UserContext.CurrentUser;
            PhotoService photoService = new PhotoService();

            if (AlbumId == 0)
            {
                album                = Album.New();
                album.DateCreated    = DateTime.UtcNow;
                album.TenantTypeId   = TenantTypeIds.Instance().User();
                album.UserId         = currentUser == null ? 0 : currentUser.UserId;
                album.OwnerId        = currentUser == null ? 0 : currentUser.UserId;
                album.Author         = currentUser == null ? string.Empty : currentUser.DisplayName;
                album.CoverId        = 0;
                album.LastUploadDate = DateTime.UtcNow;
            }
            else
            {
                album = photoService.GetAlbum(this.AlbumId);
            }
            album.LastModified  = DateTime.UtcNow;
            album.Description   = Description ?? string.Empty;
            album.AlbumName     = AlbumName;
            album.PrivacyStatus = PrivacyStatus;
            return(album);
        }
Пример #2
0
        public Photo AsPhoto()
        {
            Photo        photo        = Photo.New();
            PhotoService photoService = new PhotoService();

            //创建
            if (PhotoId == 0)
            {
                Album album = photoService.GetAlbum(this.AlbumId);
                photo.AlbumId       = this.AlbumId;
                photo.TenantTypeId  = album.TenantTypeId;
                photo.OwnerId       = album.OwnerId;
                photo.UserId        = album.UserId;
                photo.Author        = photo.User != null ? photo.User.DisplayName : album.Author;
                photo.OriginalUrl   = string.Empty;
                photo.RelativePath  = string.Empty;
                photo.AuditStatus   = AuditStatus.Pending;
                photo.PrivacyStatus = album.PrivacyStatus;
                photo.IsEssential   = false;
            }
            else
            {
                photo = photoService.GetPhoto(this.PhotoId);
            }
            photo.Description = Formatter.FormatMultiLinePlainTextForStorage(this.Description, false) ?? string.Empty;
            return(photo);
        }
Пример #3
0
        /// <summary>
        /// 查看照片
        /// </summary>
        /// <remarks>
        /// 符合照片隐私设置(所属相册的隐私设置)的人或管理员可以查看照片
        /// </remarks>
        public static bool Photo_View(this Authorizer authorizer, Photo photo)
        {
            PhotoService photoService = new PhotoService();
            Album        album        = photoService.GetAlbum(photo.AlbumId);

            if (album == null)
            {
                return(false);
            }
            if (album.PrivacyStatus == PrivacyStatus.Public)
            {
                return(true);
            }

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (album.UserId == currentUser.UserId || authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                return(true);
            }

            if (album.PrivacyStatus == PrivacyStatus.Private)
            {
                return(false);
            }

            ContentPrivacyService contentPrivacyService = new ContentPrivacyService();

            if (contentPrivacyService.Validate(album, currentUser.UserId))
            {
                return(true);
            }

            return(false);
        }