public ActionResult UploadPic(ShopImgModel model) { JsonModel jm = new JsonModel(); try { //门店BLL IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL"); var shopInfo = shopBll.GetEntity(index => index.Id == model.Id); //图片路径 string PathList = shopInfo.ImgPath; //缩略图路径 string ThumPathList = shopInfo.ImgThumbnail; for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; if (file != null) { var fileName = DateTime.Now.ToFileTime() + Path.GetExtension(file.FileName); //判断图片路径是否存在 if (!Directory.Exists(Server.MapPath(ConstantParam.SHOP_IMG_DIR))) { Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_IMG_DIR)); } //判断缩略图路径是否存在 if (!Directory.Exists(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR))) { Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR)); } //保存图片 var path = Path.Combine(Server.MapPath(ConstantParam.SHOP_IMG_DIR), fileName); file.SaveAs(path); //生成缩略图 string thumpFile = DateTime.Now.ToFileTime() + ".jpg"; var thumpPath = Path.Combine(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR), thumpFile); PropertyUtils.getThumImage(path, 18, 3, thumpPath); PathList += ConstantParam.SHOP_IMG_DIR + fileName + ";"; ThumPathList += ConstantParam.SHOP_THUM_IMG_DIR + thumpFile + ";"; } } // 更新图片 shopInfo.ImgPath = PathList; shopInfo.ImgThumbnail = ThumPathList; shopInfo.UpdateTime = DateTime.Now; // 保存到数据库 shopBll.Update(shopInfo); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } catch (Exception e) { jm.Msg = e.Message; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult UploadPic(int id) { //门店BLL IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL"); var shopInfo = shopBll.GetEntity(index => index.Id == id); ShopImgModel shopImgModel = new ShopImgModel(); shopImgModel.Id = id; if (shopInfo.ImgPath != null && shopInfo.ImgThumbnail != null) { List <string> imgPaths = shopInfo.ImgPath.Split(new char[] { ';' }).ToList(); List <string> thumbImgPaths = shopInfo.ImgThumbnail.Split(new char[] { ';' }).ToList(); shopImgModel.ImgPathArray = imgPaths; shopImgModel.ImgThumbPathArray = thumbImgPaths; } return(View(shopImgModel)); }