Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 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());
        }