Exemplo n.º 1
0
        public string Edit(int eid, string title, string minprice, string minarea, int housetype, string remark, string linkman, string tel, string county, string habitableroom)
        {
            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            int userid = User.userid;

            using (shhouseEntities db = new shhouseEntities())
            {
                try
                {
                    int countyid = 0;
                    try
                    {
                        countyid = db.Database.SqlQuery <int>(@"select areaid from dbo.base_area where  areaname=@county", new SqlParameter[] { new SqlParameter("@county", county) }).First();
                    }
                    catch
                    { }

                    house_require_wuxi myhouse_require_wuxi = db.house_require_wuxi.Find(eid);
                    if (userid != myhouse_require_wuxi.userid)
                    {
                        return(JsonConvert.SerializeObject(new repmsg
                        {
                            state = 2,
                            msg = "非本人信息不能修改",
                            data = null
                        }));
                    }

                    myhouse_require_wuxi.countyid      = countyid;
                    myhouse_require_wuxi.title         = title;
                    myhouse_require_wuxi.minprice      = minprice;
                    myhouse_require_wuxi.minarea       = minarea;
                    myhouse_require_wuxi.habitableroom = habitableroom;
                    myhouse_require_wuxi.rentype       = 0;
                    myhouse_require_wuxi.housetype     = housetype;
                    myhouse_require_wuxi.remark        = remark;
                    myhouse_require_wuxi.linkman       = linkman;
                    myhouse_require_wuxi.tel           = linkman + ",," + tel;

                    int isok = db.SaveChanges();
                    if (isok > 0)
                    {
                        return(JsonConvert.SerializeObject(new repmsg
                        {
                            state = 1,
                            msg = "修改成功",
                            data = eid
                        }, timeFormat));
                    }
                    else
                    {
                        return(JsonConvert.SerializeObject(new repmsg
                        {
                            state = 2,
                            msg = "修改失败",
                            data = null
                        }));
                    }
                }
                catch
                {
                    return(JsonConvert.SerializeObject(new repmsg
                    {
                        state = 0,
                        msg = "修改失败,请稍后再试"
                    }));
                }
            }
        }
Exemplo n.º 2
0
        public string Add(
            string title, string minprice, string minarea, int housetype, string remark, string linkman,
            string tel, string county, string habitableroom)
        {
            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            int      userid   = User.userid;
            DateTime time     = DateTime.Now;
            string   addtime  = time.ToString();
            int      unixdate = Utils.GetUnixNum(time);
            string   addip    = Utils.GetRealIP();
            int      _hid     = 0;

            using (shhouseEntities db = new shhouseEntities())
            {
                try
                {
                    int countyid = 0;
                    try
                    {
                        countyid = db.Database.SqlQuery <int>(@"select areaid from dbo.base_area where  areaname=@county", new SqlParameter[] { new SqlParameter("@county", county) }).First();
                    }
                    catch
                    { }
                    house_require_wuxi myhouse_require_wuxi = new house_require_wuxi();
                    myhouse_require_wuxi.userid        = userid;
                    myhouse_require_wuxi.countyid      = countyid;
                    myhouse_require_wuxi.title         = title;
                    myhouse_require_wuxi.minprice      = minprice;
                    myhouse_require_wuxi.minarea       = minarea;
                    myhouse_require_wuxi.habitableroom = habitableroom;
                    myhouse_require_wuxi.rentype       = 0;
                    myhouse_require_wuxi.housetype     = housetype;
                    myhouse_require_wuxi.remark        = remark;
                    myhouse_require_wuxi.linkman       = linkman;
                    myhouse_require_wuxi.tel           = linkman + ",," + tel;
                    myhouse_require_wuxi.hitcount      = 0;
                    myhouse_require_wuxi.isdel         = 0;
                    myhouse_require_wuxi.addtime       = time;
                    myhouse_require_wuxi.unixdate      = unixdate;
                    myhouse_require_wuxi.addip         = addip;
                    db.house_require_wuxi.Add(myhouse_require_wuxi);
                    db.SaveChanges();
                    int eid = myhouse_require_wuxi.eid;

                    if (eid > 0)
                    {
                        // 添加积分
                        appUserScore.ScoreAdd(userid.ToString(), userscore.suggestRent, "app求租房源积分");

                        return(JsonConvert.SerializeObject(new repmsg
                        {
                            state = 1,
                            msg = "发布成功",
                            data = eid
                        }, timeFormat));
                    }
                    else
                    {
                        return(JsonConvert.SerializeObject(new repmsg
                        {
                            state = 2,
                            msg = "发布失败",
                            data = null
                        }));
                    }
                }
                catch
                {
                    return(JsonConvert.SerializeObject(new repmsg
                    {
                        state = 0,
                        msg = "发布失败,请稍后再试"
                    }));
                }
            }
        }