Beispiel #1
0
        public ActionResult submitHouse(House house)
        {
            System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;

            User user = Session["user"] as My.RentingSystem.Model.User;

            house.isRecommend = "0";
            house.pubPerson   = user.username;
            DateTime date = DateTime.Now;
            string   now  = date.ToString("yyyyMMdd");

            house.time  = now;
            house.state = "0";
            house.audit = "0";
            House h = HouseService.AddEntity(house);

            if (files.Count == 0)
            {
                return(View());
            }
            for (int i = 0; i < files.AllKeys.Count(); i++)
            {
                if (files.AllKeys[i].Equals("images"))
                {
                    if (files[i].FileName.Length > 0)
                    {
                        System.Web.HttpPostedFile postedfile = files[i];
                        string filePath = "";
                        var    ext      = Path.GetExtension(postedfile.FileName);
                        var    fileName = h.hid + "_" + System.Guid.NewGuid().ToString("N") + ext;
                        // 组合文件存储的相对路径
                        filePath = "/Upload/images/" + fileName;
                        // 将相对路径转换成物理路径
                        var path = Server.MapPath(filePath);
                        postedfile.SaveAs(path);
                        string fex = Path.GetExtension(postedfile.FileName);
                        PictureService.AddEntity(new Picture {
                            hid  = h.hid,
                            path = filePath
                        });
                    }
                }
            }


            //HttpPostedFileBase imageName = Request.Files["images"];
            //string fileName = imageName.FileName;

            //Console.WriteLine();
            Session["city"] = Session["rentCity"];
            return(RedirectToAction("Index", "Home"));
        }
        public JsonResult addHouse(string user, string area,
                                   string price,
                                   string pay,
                                   string unitType,
                                   string floor,
                                   string community,
                                   string type,
                                   string houseDesc,
                                   string region
                                   )
        {
            System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;

            House house = new House();

            house.isRecommend = "0";
            house.pubPerson   = user;
            DateTime date = DateTime.Now;
            string   now  = date.ToString("yyyyMMdd");

            house.time  = now;
            house.state = "0";

            house.area      = Convert.ToInt32(area);
            house.price     = Convert.ToInt32(price);
            house.pay       = pay;
            house.unitType  = unitType;
            house.floor     = floor;
            house.community = community;
            house.type      = type;
            house.houseDesc = houseDesc;
            house.region    = region;
            house.audit     = "1";

            House h = HouseService.AddEntity(house);

            //if (files.Count == 0)
            //    return View();
            for (int i = 0; i < files.AllKeys.Count(); i++)
            {
                if (files.AllKeys[i].Equals("images"))
                {
                    if (files[i].FileName.Length > 0)
                    {
                        System.Web.HttpPostedFile postedfile = files[i];
                        string filePath = "";
                        var    ext      = Path.GetExtension(postedfile.FileName);
                        var    fileName = h.hid + "_" + System.Guid.NewGuid().ToString("N") + ext;
                        // 组合文件存储的相对路径
                        filePath = "/Upload/images/" + fileName;
                        // 将相对路径转换成物理路径
                        var path = Server.MapPath(filePath);
                        postedfile.SaveAs(path);
                        string fex = Path.GetExtension(postedfile.FileName);
                        PictureService.AddEntity(new Picture
                        {
                            hid  = h.hid,
                            path = filePath
                        });
                    }
                }
            }


            return(Json("success", JsonRequestBehavior.AllowGet));
        }