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()); }
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 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()); }