Esempio n. 1
0
        public async Task <IResultModel> CrawlInsert(IList <AreaCrawlingModel> list)
        {
            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var m in list)
                {
                    var entity = _mapper.Map <AreaEntity>(m);
                    await CrawlingInsert(entity, m.Children, uow);
                }

                uow.Commit();
            }

            return(ResultModel.Success());
        }
Esempio n. 2
0
        public async Task <IResultModel <AttachmentUploadResultModel> > Upload(AttachmentUploadModel model, FileInfo fileInfo)
        {
            var result = new ResultModel <AttachmentUploadResultModel>();
            var entity = new AttachmentEntity
            {
                Module   = model.Module,
                Group    = model.Group,
                FileName = model.Name.NotNull() ? model.Name : fileInfo.FileName,
                SaveName = fileInfo.SaveName,
                Ext      = fileInfo.Ext,
                Md5      = fileInfo.Md5,
                Path     = fileInfo.Path,
                FullPath = Path.Combine(fileInfo.Path, fileInfo.SaveName),
                Size     = fileInfo.Size.Size,
                SizeCn   = fileInfo.Size.ToString()
            };

            var mediaType = await _mediaTypeRepository.GetByExt(fileInfo.Ext);

            if (mediaType != null)
            {
                entity.MediaType = mediaType.Value;
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                if (await _repository.AddAsync(entity))
                {
                    //如果需要授权访问附件,需要添加拥有者关联信息
                    var ownerEntity = new AttachmentOwnerEntity
                    {
                        AttachmentId = entity.Id,
                        AccountId    = model.AccountId
                    };
                    if (!model.Auth || await _ownerRepository.AddAsync(ownerEntity, uow))
                    {
                        uow.Commit();

                        var resultModel = _mapper.Map <AttachmentUploadResultModel>(entity);

                        return(result.Success(resultModel));
                    }
                }
            }

            return(result.Failed("上传失败"));
        }