public ActionResult DoAddGoods(Shop_Photo photo,Shop_Goods goods) { #region 上传图片 //上传和返回(保存到数据库中)的路径 string uppath = string.Empty; string savepath = string.Empty; if (Request.Files.Count > 0) { // HttpPostedFileBase imgFile = Request.Files["imgName"]; //if (imgFile != null) //{ for (int i = 0; i < Request.Files.Count; i++) { //创建图片新的名称 string nameImg = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //获得上传图片的路径 // string strPath = imgFile.FileName[i].ToString(); var httpPostedFileBase = Request.Files[i]; if (httpPostedFileBase != null) { string strPath = httpPostedFileBase.FileName.ToString(); //获得上传图片的类型(后缀名) string type = strPath.Substring(strPath.LastIndexOf(".") + 1).ToLower(); if (ValidateImg(type)) { //拼写数据库保存的相对路径字符串 savepath = "../../../Uploads/Files/"; savepath += nameImg + "." + type; //拼写上传图片的路径 uppath = Server.MapPath("~/Uploads/Files/"); uppath += nameImg + "." + type; //上传图片 httpPostedFileBase.SaveAs(uppath); } else { return Content("<script>alert('请上传正确的格式图片');location.href = '/shop/shop/apply';</script>"); } } photo.PhotoURL = savepath; photo.PhontName = nameImg; photo.BoolYX = true; //} } } #endregion goods.StoreId = Convert.ToInt32(Session["stroeid"]); if (BuildFactory.GoodsFactory().Apply(goods,photo)) { return Content("<script>alert('添加成功');window.opener=null;window.close();</script>"); } ; return Content("<script>alert('添加失败,请重新申请');location.href = '/shop/shop/addgoods';</script>"); }
public ContentResult DoApply(Shop_Photo photo, Shop_People people, Shop_Store shop) { #region 上传图片 //上传和返回(保存到数据库中)的路径 string uppath = string.Empty; string savepath = string.Empty; if (Request.Files.Count > 0) { // HttpPostedFileBase imgFile = Request.Files["imgName"]; //if (imgFile != null) //{ for (int i = 0; i < Request.Files.Count; i++) { //创建图片新的名称 string nameImg = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //获得上传图片的路径 // string strPath = imgFile.FileName[i].ToString(); var httpPostedFileBase = Request.Files[i]; if (httpPostedFileBase != null) { string strPath = httpPostedFileBase.FileName.ToString(); //获得上传图片的类型(后缀名) string type = strPath.Substring(strPath.LastIndexOf(".") + 1).ToLower(); if (ValidateImg(type)) { //拼写数据库保存的相对路径字符串 savepath = "../../Uploads/Files/"; savepath += nameImg + "." + type; //拼写上传图片的路径 uppath = Server.MapPath("~/Uploads/Files/"); uppath += nameImg + "." + type; //上传图片 httpPostedFileBase.SaveAs(uppath); } else { return Content("<script>alert('请上传正确的格式图片');location.href = '/shop/shop/apply';</script>"); } } photo.PhotoURL = savepath; photo.PhontName = nameImg; photo.BoolYX = true; //} } } #endregion shop.StoreUser =((UsersEntity)Session["User"]).NickName; shop.AddTime = DateTime.Now; people.BoolLX = true; shop.BoolYX = true; shop.StoreOrde = 0; if (BuildFactory.AppylyStroeFactory().Apply(photo, people, shop)) { return Content("<script>alert('请等待管理员审核通知审核结果将发至您的邮箱,请注意查收.');location.href = '/index';</script>"); } ; return Content("<script>alert('申请失败,请重新申请');location.href = '/shop/shop/apply';</script>"); // return null(); }