Example #1
0
        // GET: HouseProperty/Details/5
        public ActionResult Details(int?id)
        {
            UserModels userModels = new UserModels();

            if (Session["userid"] != null)
            {
                userModels         = db.User.Find(Session["userid"]);
                ViewBag.userModels = userModels;
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            else if (!userFun.isUsersHP(userModels, id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HousePropertyModels housePropertyModels = db.HousePropertyModels.Find(id);

            if (housePropertyModels == null)
            {
                return(HttpNotFound());
            }
            CitiesModels    citiesModels    = db.Cities.Where(m => m.cityid == housePropertyModels.area.cityid).FirstOrDefault();
            ProvincesModels provincesModels = db.Provinces.Where(m => m.provinceid == citiesModels.provinceid).FirstOrDefault();

            housePropertyModels.adress = provincesModels.province + citiesModels.city + housePropertyModels.area.area + housePropertyModels.adress;
            return(View(housePropertyModels));
        }
Example #2
0
        public ActionResult Buy(int?id)
        {
            Dictionary <string, int> d = new Dictionary <string, int>();

            if (id == null)
            {
                d.Add("ret", -1);
                return(Json(d, JsonRequestBehavior.AllowGet));
            }
            UserModels userModels = new UserModels();

            if (Session["userid"] != null)
            {
                userModels         = db.User.Find(Session["userid"]);
                ViewBag.userModels = userModels;
            }
            else
            {
                d.Add("ret", -2);
                return(Json(d, JsonRequestBehavior.AllowGet));
            }
            if (userFun.isUsersHP(userModels, id))
            {
                d.Add("ret", -3);
                return(Json(d, JsonRequestBehavior.AllowGet));
            }
            HousePropertyModels hp = db.HousePropertyModels.Find(id);
            OrderModels         om = new OrderModels();

            om.status        = 0;
            om.startTime     = DateTime.Now;
            om.buyer         = db.User.Find(Session["userid"]);
            om.seller        = hp.owner;
            om.houseProperty = hp;
            db.Order.Add(om);
            hp.status = 3;
            db.HousePropertyModels.Attach(hp);
            db.Entry(hp).Property(m => m.status).IsModified = true;
            db.SaveChanges();
            d.Add("ret", 1);
            return(Json(d, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult Buy(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserModels userModels = new UserModels();

            if (Session["userid"] != null)
            {
                userModels         = db.User.Find(Session["userid"]);
                ViewBag.userModels = userModels;
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
            if (userFun.isUsersHP(userModels, id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HousePropertyModels hp = db.HousePropertyModels.Find(id);
            OrderModels         om = new OrderModels();

            om.status        = 0;
            om.startTime     = DateTime.Now;
            om.buyer         = db.User.Find(Session["userid"]);
            om.seller        = hp.owner;
            om.houseProperty = hp;
            db.Order.Add(om);
            hp.status = 3;
            db.HousePropertyModels.Attach(hp);
            db.Entry(hp).Property(m => m.status).IsModified = true;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }