コード例 #1
0
        public async Task <List <FileAttachmentEntity> > GetTravelFileListByTravelId(int travelId)
        {
            var travelImgList = travelFileAttachmentRepository.GetModels(a => a.travelId == travelId);
            var imgList       = new List <FileAttachmentEntity>();

            foreach (var item in travelImgList)
            {
                FileAttachmentEntity fileAttachment = await fileAttachmentRepository.GetSingleModelAsync(a => a.id == item.fileAttachmentId);

                imgList.Add(fileAttachment);
            }
            return(imgList);
        }
コード例 #2
0
        /// <summary>
        /// Creates a media attachment.
        /// </summary>
        /// <param name="type">The media type.</param>
        /// <param name="identifier">The media identifier to specify the media source.</param>
        /// <returns></returns>
        public MessageOptionalElementSetter CreateMediaAttachment(MediaAttachmentType type, MediaIdentifier identifier)
        {
            CheckIfAttachmentAlreadyBuilt();

            TemplateBuilding = true;

            var payload = new MediaPayloadEntity();

            identifier.AddValuesToPayloadEntity(payload);

            IMessageAttachmentEntity attachment;

            switch (type)
            {
            case MediaAttachmentType.Audio:
                attachment = new AudioAttachmentEntity
                {
                    Payload = payload
                };
                break;

            case MediaAttachmentType.Image:
                attachment = new ImageAttachmentEntity
                {
                    Payload = payload
                };
                break;

            case MediaAttachmentType.Video:
                attachment = new VideoAttachmentEntity
                {
                    Payload = payload
                };
                break;

            case MediaAttachmentType.File:
                attachment = new FileAttachmentEntity
                {
                    Payload = payload
                };
                break;

            default:
                throw new MediaAttachmentTypeNotSupportedException(type);
            }

            MessageEntity.Attachment = attachment;
            TemplateBuilding         = false;

            return(new MessageOptionalElementSetter(this));
        }
コード例 #3
0
        public async Task <ActionResult <List <FileAttachmentEntity> > > UploadImageList(List <IFormFile> files)
        {
            var fileAttachmentEntities = new List <FileAttachmentEntity>();
            var successCount           = 0;

            foreach (var formFile in files)
            {
                string[] extendFileName =
                { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".BMP", ".JPEG", ".PNG", ".JPG", ".GIF" };
                var stream   = formFile.OpenReadStream();
                var fileType = formFile.FileName.Substring(formFile.FileName.IndexOf('.'));
                var fileName =
                    EncryptProvider.Md5(formFile.FileName + DateTime.Now.ToString(CultureInfo.CurrentCulture));
                if (!extendFileName.Contains(fileType))
                {
                    continue;
                }
                //加密文件同赋予新路径
                var filepath         = "attachment/" + fileName + fileType;
                var attachmentEntity = new FileAttachmentEntity()
                {
                    createDate = DateTime.Now,
                    fileExt    = fileType,
                    operatorId = -1,
                    fileName   = fileName,
                    //文件获取的路径返回
                    path = "https://" + _bucketName + "." + _endPoint + "/" + filepath
                };
                if (!await _fileAttachmentService.AddEntityAsync(attachmentEntity))
                {
                    continue;
                }
                if (!FileHelper.PushImg(stream, filepath))
                {
                    continue;
                }
                successCount++;
                fileAttachmentEntities.Add(attachmentEntity);
            }

            return(Ok(new { count = successCount, result = fileAttachmentEntities }));
        }