/// <summary> /// 说明:初始化调用构造函数后可能不可用的数据。 /// </summary> /// <param name="requestContext"></param> protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); SpeechInfoBLL bll = new SpeechInfoBLL(); citys = bll.GetCitys(); WorkContext.IsHttpAjax = WebHelper.IsAjax(); WorkContext.Url = WebHelper.GetUrl(); WorkContext.UrlReferrer = WebHelper.GetUrlReferrer(); WorkContext.IP = WebHelper.GetIP(); // WebHelper.GetIP(); if (string.IsNullOrWhiteSpace(WorkContext.IP) || WorkContext.IP == "127.0.0.1") { WorkContext.CityName = "重庆市"; } else { //测试地址搜索#region 测试地址搜索 IPScaner objScan = new IPScaner(); string ip = Request.UserHostAddress.ToString(); objScan.DataPath = Server.MapPath("/App_data/qqwry.Dat"); objScan.IP = WorkContext.IP; //"113.200.29.90"; string addre = objScan.IPLocation(); int IndexofA = addre.IndexOf("省") + 1; WorkContext.CityName = addre.Substring(IndexofA); } UsersEntity userInfo = new UsersEntity(); Guid uid = ShopUtils.GetUidCookie(); //获得保存在cookie中的密码 string encryptPwd = ShopUtils.GetCookiePassword(); UsersBLL userBll = new UsersBLL(); if (Session["User"] != null) { CurrentUser = Session["User"] as UsersEntity; userInfo = CurrentUser; } else { userInfo = userBll.GetPartUserByUidAndPwd(uid); // requestContext.HttpContext.Response.Write("<script>alert('登录超时!');window.location.reload();</script>"); } if (userInfo != null && !Guid.Empty.Equals(userInfo.Id)) { WorkContext.Uid = userInfo.Id; WorkContext.Password = userInfo.Password; WorkContext.UserEmail = userInfo.Email; WorkContext.NickName = string.IsNullOrWhiteSpace(userInfo.NickName) ? userInfo.Email : userInfo.NickName; } //从cookie中获取用户的基本信息 }
public ActionResult Save(SpeechInfoEntity model) { try { SpeechInfoBLL bll = new SpeechInfoBLL(); IPScaner objScan = new IPScaner(); string ip = Request.UserHostAddress.ToString(); objScan.DataPath = Server.MapPath("/App_data/qqwry.Dat"); objScan.IP = WorkContext.IP; //"113.200.29.90"; string addre = objScan.IPLocation(); int IndexofA = addre.IndexOf("省") + 1; var ct = addre.Substring(0,IndexofA); var sourceaddr = addre; var citys= bll.GetCitys(); if (citys.FirstOrDefault(s => s.CityName == ct) == null) { ct = "重庆市"; } model.SourceCity = sourceaddr; model.City = ct; model.FromUser = WorkContext.Uid; model.IsVip = Convert.ToByte(Guid.Empty.Equals(WorkContext.Uid) ? 0 : 1); model.SumbitTime = DateTime.Now; model.State = 1;//-1为删除状态,1表示正常 if (bll.Insert(model, null)) { return AjaxResult("ok", "发送成功!", false); } else { return AjaxResult("err", "发送失败!", false); } } catch (Exception ex) { return AjaxResult("err", "发送失败!" + ex.ToString(), false); throw; } }
public ActionResult Save(SpeechInfoEntity model) { try { var city = ""; //统计当前发言人的发言次数 //if (Session["User"] != null) //{ // UsersEntity user = Session["User"] as UsersEntity; // //获取当前这个人的这个小时发言的数量 string uid = string.Empty; if (Session["User"] != null) { UsersEntity user = Session["User"] as UsersEntity; uid = user.Id.ToString(); } else { uid = ShopUtils.GetBSPCookie("bsp"); if (string.IsNullOrEmpty(uid.ToString())) { uid = Guid.NewGuid().ToString(); ShopUtils.SetBSPCookie("bsp", uid); } } SpeechInfoBLL bll = new SpeechInfoBLL(); IPScaner objScan = new IPScaner(); string ip = Request.UserHostAddress.ToString(); objScan.DataPath = Server.MapPath("/App_data/qqwry.Dat"); objScan.IP = WorkContext.IP; //"113.200.29.90"; string addre = objScan.IPLocation(); int IndexofA = addre.IndexOf("省") + 1; var ct = addre.Substring(0,IndexofA); var sourceaddr = addre; var citys = bll.GetCitys(); if (citys.FirstOrDefault(s => s.CityName == ct) == null) { ct = "重庆市"; } SpeechInfoBLL bill = new SpeechInfoBLL(); if (!string.IsNullOrEmpty(uid)) { int num = bill.GetSpeechCount(new Guid(uid)); if (num >= 3) { return AjaxResult("err", "发送失败一小时内最多能发3条!", false); } } model.SourceCity = sourceaddr; model.FromUser = new Guid(uid); model.IsVip = Convert.ToByte(Guid.Empty.Equals(new Guid(uid)) ? 0 : 1); model.SumbitTime = DateTime.Now; model.State = 1; //-1为删除状态,1表示正常 model.City = ct; // SpeechInfoBLL bll = new SpeechInfoBLL(); if (bll.Insert(model, null)) { return AjaxResult("ok", "发送成功!", false); } else { return AjaxResult("ok", "发送失败!", false); } //} //return AjaxResult("err", "请登陆后发信息!", false); } catch (Exception ex) { //return AjaxResult("err", "发送失败!" + ex.ToString(), false); throw; } }