コード例 #1
0
        public IActionResult AddSeedAndImg([FromBody] FileUpDownLoadToByteDto dto)
        {
            if (dto.Bytes == null || dto.FileName == null)
            {
                return(BadRequest("空异常"));
            }
            FilesPrint fhelp   = new FilesPrint();
            string     fileUrl = fhelp.PrintFileCreate(ServiceConfigs.FileUpDirectory, dto.Bytes);

            if (fileUrl == null)
            {
                return(StatusCode(500, "存储错误"));
            }
            if (_productRepository.GetSeed(dto.SeedID) == null)
            {
                return(StatusCode(500, "不存在该编号产品"));
            }
            var model = new FileUpDownload()
            {
                FileClass = dto.FileClass,
                FileName  = dto.FileName,
                FileUrl   = fileUrl,

                seed = _productRepository.GetSeed(dto.SeedID)
            };

            _productRepository.AddFile(model);
            if (!_productRepository.Save())
            {
                return(StatusCode(500, "上传失败,转储数据库异常"));
            }
            return(NoContent());
        }
コード例 #2
0
        public IActionResult PostSeedImg([FromBody] SeedAndImgDto seedDto)
        {
            if (seedDto == null)
            {
                return(BadRequest());
            }
            var model = new Seed
            {
                SellerID    = seedDto.SellerID,
                Species     = seedDto.Species,
                Brand       = seedDto.Brand,
                Details     = seedDto.Details,
                SeedClass   = seedDto.SeedClass,
                Exhibitions = seedDto.Exhibitions,
                Name        = seedDto.Name,

                Price = seedDto.Price
            };

            if (seedDto.FileUpDownLoadDto != null)
            {
                FileUpDownload fileUpDownload = new FileUpDownload
                {
                    FileClass = seedDto.FileUpDownLoadDto.FileClass,
                    FileName  = seedDto.FileUpDownLoadDto.FileName,
                    seed      = _productRepository.GetSeed(seedDto.SeedID),
                };

                try
                {
                    string     fileurl;
                    FilesPrint fp = new FilesPrint();
                    fileurl = fp.PrintFileCreate(ServiceConfigs.FileUpDirectory, seedDto.FileUpDownLoadDto.Bytes);
                    fileUpDownload.FileUrl = fp.readURL(fileurl);
                    model.fileUpDownloads.Add(fileUpDownload);
                }
                catch (Exception)
                {
                    return(StatusCode(500, "传入字节流文件错误"));

                    throw;
                }
            }

            _productRepository.AddSeed(model);
            if (!_productRepository.Save())
            {
                return(StatusCode(500, "存储失败"));
            }
            return(Ok());
        }