public PersonDto GetById(string personId) { Stopwatch sw = new Stopwatch(); sw.Start(); var entity = _personRepository.GetById(personId); sw.Stop(); var perTotal = sw.ElapsedMilliseconds; if (entity != null) { var model = entity.MapTo <PersonDto>(); var parentPath = HostingEnvironment.MapPath("~"); sw.Restart(); var imgfile = parentPath + model.CertificateIPic; if (File.Exists(imgfile)) { Image img = Image.FromFile(imgfile); model.CertificateIIMG = ImgUtil.ImgToByt(img); } sw.Stop(); var img1total = sw.ElapsedMilliseconds; sw.Restart(); var idIimgfile = parentPath + model.IDCardPic; if (File.Exists(idIimgfile)) { Image img = Image.FromFile(idIimgfile); model.IDCardImg = ImgUtil.ImgToByt(img); } sw.Stop(); var img1tota2 = sw.ElapsedMilliseconds; sw.Restart(); var faceIimgfile = parentPath + model.FacePic; if (File.Exists(faceIimgfile)) { Image img = Image.FromFile(faceIimgfile); model.FaceImg = ImgUtil.ImgToByt(img); } sw.Stop(); var img1tota3 = sw.ElapsedMilliseconds; return(model); } else { return(null); } }
public IHttpActionResult GetIDImgById(string personId) { var img = personService.GetIDImgById(personId); if (img != null) { return(Ok(new { code = 0, msg = "success", data = ImgUtil.ImgToByt(img) })); } else { return(Ok(new { code = 1, msg = "数据不存在" })); } }