/// <summary> /// 遍历我的回答过的帖子,即回帖 /// Creator:Simple /// </summary> /// <returns></returns> public ActionResult myAnsweres() { 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"] = "myAnsweres";//当前action名 ReplyPost_bll replyPost_bll = new ReplyPost_bll(); List <ReplyPost_model> replyPost_modelList = new List <ReplyPost_model>(); replyPost_modelList = replyPost_bll.GetShortReplyPostData(userId);//获取用户的回帖数据 return(View(replyPost_modelList)); }
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> /// 遍历我的回答过的帖子,即回帖 /// </summary> /// <returns></returns> public ActionResult myAnsweres() { 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; ReplyPost_bll replyPost_bll = new ReplyPost_bll(); List <ReplyPost_model> replyPost_modelList = new List <ReplyPost_model>(); replyPost_modelList = replyPost_bll.GetShortReplyPostData(userId);//获取用户的回帖数据 return(View(replyPost_modelList)); }
/// <summary> /// 对主贴的回帖 /// </summary> /// <returns></returns> public ActionResult MakePostReply() { ////--------先把前端传回来的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('&'); //对前端传回来的数据进行分割,提取出文本框里的html数据 string contentData = datas[0].ToString(); //data[0]为变量名为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/HuiTieHtml/") + fileName; //物理路径 while (System.IO.File.Exists(fileNamePath)) //先判断文件是否存在,若存在:更换文件名 { datetime = DateTime.Now; fileName = datetime.ToString("yyyyMMddHHmmss_ffff") + ".html"; fileNamePath = Server.MapPath("~/StaticHtml/HuiTieHtml/") + 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成功 ///----------/将数据保存到数据库里tb_ReplyPost (主贴编号 回帖者Id ///回帖内容的前200字符 点赞数 日期 回帖的静态html) int postId = Convert.ToInt32(Request["hidPostId"]); //主贴id int supportCount = 0; //点赞数 string replyUserName = Request["hidHuiTieUserName"].ToString(); User_bll user_bll = new User_bll(); int replyUserId = user_bll.GetUserId(replyUserName); //回帖者id string editorContent = datas[3].ToString(); //回帖内容的纯文本包含图片,data[3]的为前端传回来的发帖内容的纯文本 (备注:不能从request["editorContent"]读取,会报错提示说存在html标签) 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); //回帖的200字符 string staticHuiTieHtml = "/StaticHtml/HuiTieHtml/" + fileName; //相对路径 ReplyPost_bll replyPost_bll = new ReplyPost_bll(); replyPost_bll.InsertReplyPost(postId, replyUserId, content200, supportCount, datetime, staticHuiTieHtml); //--------回帖数据保存成功 //////获取回帖里的所有图片的路径,并且将图片路径保存到数据库里tb_PostPhoto (PostPhoto_PostType=) int replyPostId = replyPost_bll.GetReplyPostId(staticHuiTieHtml); //根据回帖的静态html路径查询数据库,得到该贴子的replyPost_Id 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) { PostPhoto_bll postPhoto_bll = new PostPhoto_bll(); if (postPhoto_bll.InsertPhotoUrl(replyPostId, strUrlList, 2) < 0) { return(Content("保存图片路径时数据库出错")); } } return(RedirectToAction("../Topic/PostDetails", new { postId = postId })); }