public IActionResult GetSeedndImg(int seedid) { if (_productRepository.GetSeed(seedid) == null) { return(StatusCode(500, "不存在")); } var model = _productRepository.GetFile(seedid); FilesPrint fhelp = new FilesPrint(); byte[] bt = fhelp.ReadFile(fhelp.readURL(model.FileUrl)); if (bt == null) { return(StatusCode(500, "读取异常")); } return(Ok(new FileUpDownLoadToByteDto { FID = model.FID, FileClass = model.FileClass, FileName = model.FileName, SeedID = model.seed.SeedID, Bytes = bt })); }
public IActionResult getSeedImg(int seedid) { if (seedid < 0) { return(BadRequest()); } var model = _productRepository.GetSeed(seedid); if (model == null) { return(StatusCode(500, "获取失败")); } //var list = new List<SeedDto>(); SeedAndImgDto seedDto = new SeedAndImgDto { SellerID = model.SellerID, Species = model.Species, Brand = model.Brand, Details = model.Details, SeedClass = model.SeedClass, Exhibitions = model.Exhibitions, MakertID = model.MakertID, MakertName = _productRepository.GetSeller(model.SellerID).MarkerName, Name = model.Name, Price = model.Price, }; var filemodel = _productRepository.GetFile(model.SeedID); FileUpDownLoadToByteDto filedto = new FileUpDownLoadToByteDto { FID = filemodel.FID, FileClass = filemodel.FileClass, FileUrl = filemodel.FileUrl, FileName = filemodel.FileName, SeedID = filemodel.seed.SeedID }; try { string Imgurl = _productRepository.GetFile(model.SeedID).FileUrl; FilesPrint fp = new FilesPrint(); filedto.Bytes = fp.ReadFile(fp.readURL(Imgurl)); seedDto.FileUpDownLoadDto = filedto; } catch (Exception) { filedto.Bytes = null; throw; } return(Ok(seedDto)); }
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()); }
public IActionResult PutSeedAndImg(int seedid, [FromBody] FileUpDownLoadToByteDto dto) { if (dto.Bytes == null || dto.FileName == null) { return(BadRequest("空异常")); } FilesPrint fhelp = new FilesPrint(); var url = _productRepository.GetFile(seedid).FileUrl; if (url == null) { StatusCode(500, "服务器文件丢失"); } ; int fileUrl = fhelp.PrintFileUpdate(fhelp.readURL(url), dto.Bytes); if (fileUrl == 0) { return(StatusCode(500, "存入失败")); } if (fileUrl == null) { return(StatusCode(500, "存储错误")); } if (_productRepository.GetSeed(dto.SeedID) == null) { return(StatusCode(500, "不存在该编号产品")); } var model = _productRepository.GetFile(dto.SeedID); model.FileClass = dto.FileClass; model.FileName = dto.FileName; model.FileUrl = dto.FileUrl; model.seed = _productRepository.GetSeed(dto.SeedID); if (!_productRepository.Save()) { return(StatusCode(500, "上传失败,转储数据库异常")); } return(NoContent()); }