示例#1
0
        public ActionResult ToEditGoods(jf_Goods goods)
        {
            jf_Goods OldGoods  = jf_Goods.GetEntityByID(goods.ID);
            string   oldImgUrl = OldGoods.Main_img;//原来的图片

            if (oldImgUrl.Contains("?"))
            {
                oldImgUrl = oldImgUrl.SubStringSafe(0, oldImgUrl.IndexOf("?"));
            }
            string msg = "";

            if (RepeatHelper.NoRepeat("jf_Goods", "GoodsName", goods.GoodsName, goods.ID) > 0)
            {
                msg         = "该礼品已存在!";
                goods.error = msg;
                return(View("EditGoods", goods));
            }
            OldGoods.GoodsName = goods.GoodsName;
            var file = Request.Files[0];

            if (file.ContentLength > 0 && file != null)
            {
                if (file.ContentLength > 5242880)
                {
                    msg         = "上传图片不能超过5MB!";
                    goods.error = msg;
                    return(View("EditGoods", goods));
                }
                if (!Directory.Exists(Server.MapPath("~/images/jf_Goods/")))
                {
                    Directory.CreateDirectory(Server.MapPath("~/images/jf_Goods/"));
                }
                string path = Request.MapPath("~/");
                string ext  = Path.GetExtension(file.FileName); //获得文件扩展名
                OldGoods.Main_img = "/images/jf_Goods/G_" + OldGoods.ID + ext;
                string saveName = OldGoods.Main_img;            //实际保存文件名

                try
                {
                    string delFile = Server.MapPath("~") + oldImgUrl;
                    System.IO.File.Delete(delFile);
                }
                catch (Exception ex) { }


                file.SaveAs(path + saveName);
            }
            OldGoods.Main_img     = OldGoods.Main_img + "?" + DateTime.Now.ToString("yyyyMMddHHmmss");
            OldGoods.SaleIntegral = goods.SaleIntegral;
            OldGoods.Quantity     = goods.Quantity;
            if (OldGoods.EditByID() > 0)
            {
                goods.error = "ok";
            }
            else
            {
                goods.error = "修改礼品失败!";
            }
            return(View("EditGoods", goods));
        }
示例#2
0
        public ContentResult GoodsDetailSave(jf_Goods goods)
        {
            jf_Goods oldGoods = jf_Goods.GetEntityByID(goods.ID);

            oldGoods.Detail      = goods.Detail;
            oldGoods.DetailTemp  = "";
            oldGoods.PublishStat = goods.PublishStat;
            int rtn = oldGoods.EditByID();

            if (rtn > 0)
            {
                return(Content("保存成功"));
            }
            return(Content("保存失败"));
        }