Beispiel #1
0
 public ActionResult CreatGoods(Goods goods)
 {
     try
     {
         HttpPostedFileBase postImage = Request.Files["GoodsPhoto"];
         string             img       = postImage.FileName.ToString();
         if (img == "")
         {
             return(Content("<script>;alert('请输入图片');history.go(-1)</script>"));
         }
         else
         {
             string filePath     = postImage.FileName;
             string filename     = filePath.Substring(filePath.LastIndexOf("\\") + 1);
             string serverpath   = Server.MapPath(@"\images\Goods\") + filename;
             string relativepath = @"/images/Goods/" + filename;
             postImage.SaveAs(serverpath);
             goods.GoodsPhoto = relativepath;
         }
         if (ModelState.IsValid)
         {
             int userid = Convert.ToInt32(Session["UserID"]);
             goods.ShopID = shopmanager.SelectShopid(userid);
             goods.Flag   = Convert.ToInt32(Request.Form["xuanze"]);
             goods.Time   = DateTime.Now;
             goodsmanager.CreateGoods(goods);
             return(Content("<script>;alert('添加成功');history.go(-1)</script>"));
         }
         else
         {
             return(Content("<script>;alert('添加失败');history.go(-1)</script>"));
         }
         return(View(goods));
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         throw dbEx;
     }
 }