Beispiel #1
0
        /// <summary>
        /// 获取对象封面图片
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <GetObjectImagesListDto> GetObjectCoverImage(SetCoverInputDto input)
        {
            var objectType           = Enum.Parse <AttachmentObjectTypes>(input.ObjectType);
            var objectAttachmentInfo = await _objectAttachmentInfoRepository.GetAllIncluding(p => p.AttachmentInfo)
                                       .Where(p =>
                                              p.ObjectId == input.ObjectId && p.ObjectType == objectType &&
                                              p.AttachmentInfo.AttachmentType == AttachmentTypes.Image)
                                       .FirstOrDefaultAsync(a => a.IsCover);

            if (objectAttachmentInfo == null)
            {
                return(new GetObjectImagesListDto());
            }
            return(new GetObjectImagesListDto
            {
                Id = objectAttachmentInfo.AttachmentInfo.Id,
                Name = objectAttachmentInfo.AttachmentInfo.Name,
                FileLength = objectAttachmentInfo.AttachmentInfo.FileLength,
                Url = objectAttachmentInfo.AttachmentInfo.Url,
                IsCover = objectAttachmentInfo.IsCover
            });
        }
Beispiel #2
0
        /// <summary>
        /// 设置封面
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public async Task SetCover(SetCoverInputDto input)
        {
            var objectType            = Enum.Parse <AttachmentObjectTypes>(input.ObjectType);
            var objectAttachmentInfos = await _objectAttachmentInfoRepository.GetAllIncluding(p => p.AttachmentInfo)
                                        .Where(p =>
                                               p.ObjectId == input.ObjectId && p.ObjectType == objectType &&
                                               p.AttachmentInfo.AttachmentType == AttachmentTypes.Image)
                                        .ToListAsync();

            var objectAttachment = objectAttachmentInfos.FirstOrDefault(a => a.IsCover);

            if (objectAttachment != null)
            {
                objectAttachment.IsCover = false;
            }
            var setObjectAttachment =
                objectAttachmentInfos.FirstOrDefault(a => a.AttachmentInfo.Url == input.AttachmentUrl);

            if (setObjectAttachment == null)
            {
                throw new UserFriendlyException();
            }
            setObjectAttachment.IsCover = true;
        }