/// <summary> ///遍历我的提问过的帖子 ///Creator:Simple /// </summary> /// <returns></returns> public ActionResult myAsks() { if (Session["userName"] == null) { return(RedirectToAction("LoginRemind", "Topic")); } LoginStatusConfig();//配置登录状态 string userName = Session["userName"].ToString(); ////获取用户等级名 Rank_bll rank_bll = new Rank_bll(); string rankNameDB = rank_bll.GetRankName(userName); //该用户数据库里的等级名 rankNameDB = rankNameDB.Trim(); //去除空格 User_bll user_bll = new User_bll(); int userId = Convert.ToInt32(user_bll.GetUserId(userName)); //通过用户名获取userId CountUser_model countUser_model = user_bll.GetCountUser(userId, rankNameDB); //获取用户的CountUser_model 数据:点赞数 关注数 粉丝数 收藏数 提问数 回帖数 特定咨询数 等 ViewData["countUser_model"] = countUser_model; ViewData["rankName"] = rankNameDB; //用户等级名 ViewData["actionName"] = "myAsks"; //当前action名 Post_bll post_bll = new Post_bll(); List <Post_model> post_modelList = post_bll.GetShortPostData(userId); //获取用户的提问过的贴子 return(View(post_modelList)); }
/// <summary> /// 主页面 /// </summary> /// <returns></returns> public ActionResult Home() { Post_bll post_bll = new Post_bll(); List <Post_model> post_modelList = post_bll.GetPost(1, 50); LoginStatusConfig(); //配置登录状态 return(View(post_modelList)); }
// // GET: /Posts/ /// <summary> /// 通过Ajax获得4个普通咨询的首张图片和前200个字符 /// </summary> /// <returns></returns> public ActionResult AjaxHomeGetPuTongPicture() { Post_bll post_bll = new Post_bll(); JavaScriptSerializer serializer1 = new JavaScriptSerializer(); string json = serializer1.Serialize(post_bll.GetFourPuTongPost()); //return Content("1"); return(Content(json));//返回一个json数据 }
/// <summary> /// 实现原贴的取消点赞 /// 成功返回1 /// 失败返回0 /// </summary> /// <returns></returns> public ActionResult AjaxPostSupportCountReduce1() { string postIdStr = Request["postId"].ToString(); int postId = Convert.ToInt32(postIdStr); Post_bll post_bll = new Post_bll(); if (post_bll.UpdateSupportCountReduce1(postId) < 1) { return(Content("0")); } return(Content("1")); }
/// <summary> /// 主页面 /// </summary> /// <returns></returns> public ActionResult Home() { if (Session["userName"] == null) { return(View("LoginRemind")); } Post_bll post_bll = new Post_bll(); List <Post_model> post_modelList = post_bll.GetPost(1, 20); LoginStatusConfig(); //配置登录状态 return(View(post_modelList)); }
/// <summary> /// 收藏帖子 /// 从前端接收4个参数提交到Post_dal /// 返回1更新成功 /// 返回0更新失败 /// 返回2提示登录 /// </summary> /// <returns></returns> public ActionResult ShouCangTieZi() { if (Session["userName"] == null) { return(Content("2")); } string userName = Request["userName"]; string postId = Request["postId"]; string postType = Request["postType"]; string Num = Request["Num"]; Post_bll post_bll = new Post_bll(); return(Content(post_bll.check_ShouCangTieZi(userName, postId, postType, Num).ToString())); }
public ActionResult PostDetails() { LoginStatusConfig(); //配置登录状态 int postId = Convert.ToInt32(Request["postId"]); //获取postId的原帖数据 Post_bll post_bll = new Post_bll(); Post_model post_mode = post_bll.GetOnePost(postId); ViewData["post_mode"] = post_mode; //获取对postId原帖的回帖数据 ReplyPost_bll replyPost_bll = new ReplyPost_bll(); List <ReplyPost_model> replyPost_modelList = replyPost_bll.GetReplyPost(postId); return(View(replyPost_modelList)); }
/// <summary> /// 实现原贴的点赞 /// 成功返回1 /// 失败返回0 /// 返回2,提示登录 /// </summary> /// <returns></returns> public ActionResult AjaxPostSupportCountAdd1() { //if (Session["userName"] == null) // return Content("2"); string postIdStr = Request["postId"].ToString(); int postId = Convert.ToInt32(postIdStr); Post_bll post_bll = new Post_bll(); if (post_bll.UpdateSupportCountAdd1(postId) < 1) { return(Content("0")); } return(Content("1")); }
/// <summary> /// 在搜索框里输入关键字搜索帖子 /// </summary> /// <returns></returns> public ActionResult SearchPosts() { string searchKeyWord = Request["searchKeyWord"].ToString(); if (Session["userName"] == null) { return(View("../Topic/LoginRemind")); } Post_bll post_bll = new Post_bll(); List <Post_model> post_modelList = post_bll.GetSearchPost(1, 20, searchKeyWord); LoginStatusConfig(); //配置登录状态 //return View(post_modelList); return(View("../Topic/Home", post_modelList)); }
/// <summary> ///遍历我的提问过的帖子 /// </summary> /// <returns></returns> public ActionResult myAsks() { if (Session["userName"] == null) { return(RedirectToAction("LoginRemind", "Topic")); } LoginStatusConfig();//配置登录状态 string userName = Session["userName"].ToString(); User_bll user_bll = new User_bll(); int userId = Convert.ToInt32(user_bll.GetUserId(userName)); //通过用户名获取userId CountUser_model countUser_model = user_bll.GetCountUser(userId); //获取用户的CountUser_model 数据:点赞数 关注数 粉丝数 收藏数 提问数 回帖数 特定咨询数 等 ViewData["countUser_model"] = countUser_model; Post_bll post_bll = new Post_bll(); List <Post_model> post_modelList = post_bll.GetShortPostData(userId);//获取用户的提问过的贴子 return(View(post_modelList)); }
public ActionResult postData() { ////先把前端传回来的content内容保存为静态页面 byte[] byteData = new byte[Request.InputStream.Length]; //定义一个字节数组保存前端传回来的Post数据全部数据 Request.InputStream.Read(byteData, 0, byteData.Length); //将流读取到byteData,InputStream读取到的是http头里的主体数据 //string postData = System.Text.Encoding.Default.GetString(byteData);//系统的默认编码为gb2312,不适用这种 string postData = System.Text.Encoding.UTF8.GetString(byteData); postData = Server.UrlDecode(postData); //对数据进行url解码 string[] datas = postData.Split('&'); //对postData数据进行分割,提取出发帖内容里的html数据 string contentData = datas[1].ToString(); //data[1]为变量名为content的内容 contentData = contentData.Substring(contentData.IndexOf('=') + 1); //去除变量名,如content=aaa,只取出aaa DateTime datetime = DateTime.Now; string fileName = datetime.ToString("yyyyMMddHHmmss_ffff") + ".html"; //定义文件名fileName string fileNamePath = Server.MapPath("~/StaticHtml/TieZiHtml/") + fileName; //物理路径 while (System.IO.File.Exists(fileNamePath)) //先判断文件是否存在,若存在:更换文件名 { datetime = DateTime.Now; fileName = datetime.ToString("yyyyMMddHHmmss_ffff") + ".html"; fileNamePath = Server.MapPath("~/StaticHtml/TieZiHtml/") + fileName; } System.IO.FileStream fs = new System.IO.FileStream(fileNamePath, System.IO.FileMode.Create); byte[] contentBytes = System.Text.Encoding.UTF8.GetBytes(contentData); //byte[] contentBytes = System.Text.Encoding.Default.GetBytes(contentData); fs.Write(contentBytes, 0, contentBytes.Length); fs.Close();//保存静态html成功 ///////将帖子数据保存到数据库 Post_bll Post = new Post_bll(); Theme_bll themeName = new Theme_bll(); People_bll User = new People_bll(); string caption = Request["question"].ToString(); string userName = Session["userName"].ToString(); int userId = User.GainUserId(userName); string theme = Request["theme"].ToString(); int themeId = themeName.CollocateThemeId(theme); string staticHtmlPath = "/StaticHtml/TieZiHtml/" + fileName; //相对路径 string editorContent = datas[3].ToString(); //data[3]的为前端传回来的发帖内容的纯文本 editorContent = editorContent.Substring(editorContent.IndexOf('=') + 1); System.Text.RegularExpressions.Regex regexImg = new System.Text.RegularExpressions.Regex(@"<img[^>]+>"); editorContent = regexImg.Replace(editorContent, "");//过滤掉editorContent里图片 int len = editorContent.Length; if (len > 200)//如果editorContent的长度超过200,取editorContent里的前两百个字符,将用于保存到数据库 { len = 200; } string content200 = editorContent.Substring(0, len); if (Post.finshInsert(caption, content200, userId, themeId, staticHtmlPath, datetime) != 1) { return(Content("保存帖子信息时数据库出错")); }//将帖子数据保存到数据库---------成功 //////获取所有图片里的图片路径,并且将图片路径保存到数据库里 System.Text.RegularExpressions.Regex regImg2 = new System.Text.RegularExpressions.Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);// 定义正则表达式用来匹配 img 标签 System.Text.RegularExpressions.MatchCollection matches = regImg2.Matches(contentData); int i = 0; string[] strUrlList = new string[matches.Count]; foreach (System.Text.RegularExpressions.Match match in matches) { strUrlList[i++] = match.Groups["imgUrl"].Value;// 取得匹配项列表 } if (strUrlList.Length >= 1) { int postId = Post.GetPostId(caption); //根据帖子的标题查询数据库,得到该贴子的postId PostPhoto_bll postPhoto_bll = new PostPhoto_bll(); if (postPhoto_bll.InsertPhotoUrl(postId, strUrlList, 1) < 0) { return(Content("保存图片路径时数据库出错")); } } return(Content("成功")); }