Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
        protected override bool UnInstall(string presentAreaKey, long ownerId)
        {
            PhotoService photoService = new PhotoService();

            photoService.DeleteUser(ownerId, string.Empty, false);
            return(true);
        }
Beispiel #4
0
 /// <summary>
 /// 获取被评论对象名称
 /// </summary>
 /// <param name="commentedObjectId">被评论对象Id</param>
 /// <param name="tenantTypeId">租户类型Id</param>
 /// <returns></returns>
 public string GetCommentedObjectName(long commentedObjectId, string tenantTypeId)
 {
     if (tenantTypeId == TenantTypeIds.Instance().Photo())
     {
         Photo photo = new PhotoService().GetPhoto(commentedObjectId);
         if (photo != null)
         {
             return(SiteUrls.FullUrl(SiteUrls.Instance().PhotoDetail(commentedObjectId)));
         }
     }
     return(string.Empty);
 }
        /// <summary>
        /// 详细页面地址
        /// </summary>
        /// <param name="itemId">推荐内容Id</param>
        /// <returns></returns>
        public string RecommendItemDetail(long itemId)
        {
            Album album = new PhotoService().GetAlbum(itemId);

            if (album == null)
            {
                return(string.Empty);
            }
            string userName = UserIdToUserNameDictionary.GetUserName(album.UserId);

            return(SiteUrls.Instance().AlbumDetailList(userName, itemId));
        }
Beispiel #6
0
        /// <summary>
        /// 详细页面地址
        /// </summary>
        /// <param name="itemId">推荐内容Id</param>
        /// <returns></returns>
        public string RecommendItemDetail(long itemId)
        {
            Photo photo = new PhotoService().GetPhoto(itemId);

            if (photo == null)
            {
                return(string.Empty);
            }
            string userName = UserIdToUserNameDictionary.GetUserName(photo.UserId);

            return(SiteUrls.Instance().PhotoDetail(itemId));
        }
Beispiel #7
0
        /// <summary>
        /// 获取被评论对象(部分)
        /// </summary>
        /// <param name="commentedObjectId"></param>
        /// <returns></returns>
        public CommentedObject GetCommentedObject(long commentedObjectId)
        {
            Photo photo = new PhotoService().GetPhoto(commentedObjectId);

            if (photo != null)
            {
                CommentedObject commentedObject = new CommentedObject();
                commentedObject.DetailUrl = SiteUrls.Instance().PhotoDetail(commentedObjectId);
                commentedObject.Name      = SiteUrls.FullUrl(SiteUrls.Instance().PhotoDetail(commentedObjectId));
                commentedObject.Author    = photo.Author;
                commentedObject.UserId    = photo.UserId;
                return(commentedObject);
            }
            return(null);
        }
Beispiel #8
0
        protected override bool Install(string presentAreaKey, long ownerId)
        {
            PhotoService photoService = new PhotoService();
            string       author       = DIContainer.Resolve <UserService>().GetFullUser(ownerId).DisplayName;
            Album        album        = Album.New();

            album.OwnerId        = ownerId;
            album.UserId         = ownerId;
            album.Author         = author;
            album.AlbumName      = "默认相册";
            album.Description    = "默认相册";
            album.AuditStatus    = AuditStatus.Success;
            album.PrivacyStatus  = PrivacyStatus.Public;
            album.TenantTypeId   = TenantTypeIds.Instance().User();
            album.LastUploadDate = DateTime.UtcNow;
            photoService.CreateAlbum(album);
            return(true);
        }
Beispiel #9
0
        /// <summary>
        /// 相册隐私状态更改,同步更改相册下隐私状态
        /// </summary>
        /// <param name="albumId"></param>
        public void UpdatePrivacyStatus(long albumId)
        {
            var dao = CreateDAO();

            dao.OpenSharedConnection();

            Album album = new PhotoService().GetAlbum(albumId);

            if (album != null)
            {
                Sql sql = Sql.Builder
                          .Append("update spb_Photos set PrivacyStatus = @0 where spb_Photos.AlbumId = @1", album.PrivacyStatus, albumId);
                dao.Execute(sql);
            }

            Sql sql_Select = Sql.Builder
                             .Select("PhotoId")
                             .From("spb_Photos");

            IEnumerable <object> photoIds = dao.FetchTopPrimaryKeys <Photo>(int.MaxValue, sql_Select);

            dao.CloseSharedConnection();

            foreach (var item in photoIds)
            {
                long id = 0;
                if (long.TryParse(item.ToString(), out id))
                {
                    RealTimeCacheHelper.IncreaseEntityCacheVersion(id);

                    //处理掉本机缓存
                    string cacheKeyOfEntity = RealTimeCacheHelper.GetCacheKeyOfEntity(id);
                    Photo  photo            = cacheService.Get <Photo>(cacheKeyOfEntity);
                    if (photo != null)
                    {
                        photo.IsEssential = true;
                    }
                }
            }
        }
Beispiel #10
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);
        }
Beispiel #11
0
        /// <summary>
        /// 删除用户在应用中的数据
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="takeOverUserName">用于接管删除用户时不能删除的内容(例如:用户创建的群组)</param>
        /// <param name="isTakeOver">是否接管被删除用户可被接管的内容</param>
        protected override void DeleteUser(long userId, string takeOverUserName, bool isTakeOver)
        {
            PhotoService photoService = new PhotoService();

            photoService.DeleteUser(userId, takeOverUserName, isTakeOver);
        }