예제 #1
0
        public async Task <IResultModel <FileDownloadModel> > Download(Guid id)
        {
            var result = new ResultModel <FileDownloadModel>();

            var attachment = await _repository.GetAsync(id);

            if (attachment == null)
            {
                return(result.Failed("附件不存在"));
            }

            if (attachment.Auth)
            {
                var has = await _ownerRepository.Exist(new AttachmentOwnerEntity { AccountId = _loginInfo.AccountId, AttachmentId = id });

                if (!has)
                {
                    return(result.Failed("您无权访问该附件"));
                }
            }

            var filePath = Path.Combine(_moduleCommonOptions.UploadPath, attachment.FullPath);

            if (!File.Exists(filePath))
            {
                return(result.Failed("文件不存在"));
            }

            return(result.Success(new FileDownloadModel(filePath, attachment.FileName, attachment.MediaType)));
        }
예제 #2
0
        public async Task <IResultModel> Edit(Guid id)
        {
            var entity = await _repository.GetAsync(id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            var model = _mapper.Map <AttachmentUpdateModel>(entity);

            return(ResultModel.Success(model));
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IResultModel> Delete(Guid id)
        {
            var entity = await _repository.GetAsync(id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            if (await _repository.DeleteAsync(id))
            {
                return(ResultModel.Success());
            }

            return(ResultModel.Failed());
        }
        public async Task <IResultModel <FileDownloadModel> > Download(Guid id, Guid accountId)
        {
            var result = new ResultModel <FileDownloadModel>();

            var attachment = await _repository.GetAsync(id);

            if (attachment == null)
            {
                return(result.Failed("附件不存在"));
            }

            if (attachment.Auth)
            {
                var has = await _ownerRepository.Exist(new AttachmentOwnerEntity { AccountId = accountId, AttachmentId = id });

                if (!has)
                {
                    return(result.Failed("无权访问"));
                }
            }

            var config   = _configProvider.Get <PathConfig>();
            var filePath = Path.Combine(config.UploadPath, attachment.FullPath);

            if (!File.Exists(filePath))
            {
                return(result.Failed("附件不存在"));
            }

            return(result.Success(new FileDownloadModel(filePath, attachment.FileName, attachment.MediaType)));
        }
        /// <summary>
        /// Sets the attachment aggregate with the assigned device ID and ports.
        /// </summary>
        /// <returns>The handle.</returns>
        /// <param name="message">Message.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public async Task <bool> Handle(SetUniCommand message, CancellationToken cancellationToken)
        {
            var attachment = await _attachmentRepository.GetAsync(message.AttachmentId);

            var attachmentBandwidth = await _attachmentBandwidthRepository.GetAsync(attachment.GetAttachmentBandwidthId());

            attachment.SetUni(message.UniName, message.UniAccessLinkIdentifiers);

            return(await _attachmentRepository.UnitOfWork.SaveEntitiesAsync());
        }
예제 #6
0
 public async Task <EntityList <AttachmentDto> > GetAsync(int page, int pageSize, string search = "")
 {
     return(await _repository.GetAsync(page, pageSize, search));
 }