Beispiel #1
0
        public ActionResult SetCoverImg(CoverImgUploadModel model)
        {
            JsonModel jm = new JsonModel();

            IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

            var shop = shopBll.GetEntity(index => index.Id == model.ShopId);

            try
            {
                //存入文件的路径
                string directory = Server.MapPath(ConstantParam.SHOP_IMG_DIR);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                //获取上传文件的扩展名
                string fileEx = Path.GetExtension(Path.GetFileName(model.CoverImgFile.FileName));
                //保存数据文件
                string fileName = DateTime.Now.ToFileTime().ToString() + fileEx;
                string savePath = Path.Combine(directory, fileName);
                model.CoverImgFile.SaveAs(savePath);
                shop.ImgPath = ConstantParam.SHOP_IMG_DIR + fileName;

                //判断缩略图路径是否存在
                if (!Directory.Exists(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR)))
                {
                    Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR));
                }
                //生成缩略图
                string thumpFile = DateTime.Now.ToFileTime() + ".jpg";

                var thumpPath = Path.Combine(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR), thumpFile);
                if (PropertyUtils.getThumImage(savePath, 18, 3, thumpPath))
                {
                    shop.ImgThumbnail = ConstantParam.SHOP_THUM_IMG_DIR + thumpFile;
                }
                shopBll.Update(shop);
            }
            catch
            {
                jm.Msg = "请求发生异常";
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult SetCoverImg(int id)
        {
            //门店BLL
            IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

            var shop = shopBll.GetEntity(index => index.Id == id);

            if (shop != null)
            {
                CoverImgUploadModel model = new CoverImgUploadModel();
                model.ShopId  = id;
                model.ImgPath = shop.ImgPath;
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }