public ActionResult SavePost([FromBody] PostInfo postInfo) { try { if (postInfo == null) { return(Ok(new { mark = "2", msg = "请求内容为空!" })); } var headerStr = Request.Headers["Authorization"]; var jwtHelper = new JWTHelper(_configuration); var user = new UserInfo { UserId = jwtHelper.GetJWTUserData(headerStr) }; postInfo.Author = user; postInfo.Status = 2; //保存 postInfo.CreateDate = DateTime.Now; postInfo.UpdateDate = DateTime.Now; if (!string.IsNullOrEmpty(postInfo.Description)) { postInfo.Description = HtmlFillter.ReplaceHtmlToBlank(postInfo.PostContent); } var result = _postService.AddPostInfo(postInfo); if (result > 0) { return(Ok(new { mark = "1", postId = result, msg = "保存成功!" })); } return(Ok(new { mark = "2", msg = "处理失败!" })); } catch (Exception ex) { return(Ok(new { mark = "2", msg = ex.Message })); } }
public ActionResult WritePost([FromBody] PostInfo postInfo) { try { if (postInfo == null) { return(Ok(new { mark = "2", msg = "请求数据不能为空!" })); } if (string.IsNullOrEmpty(postInfo.PostTitle)) { return(Ok(new { mark = "2", msg = "标题不能为空!" })); } if (postInfo.SecondCategory.SecondCategoryId <= 0) { return(Ok(new { mark = "2", msg = "分类为空!" })); } if (string.IsNullOrEmpty(HtmlFillter.ReplaceHtmlToBlankExCludetImg(postInfo.PostContent.Trim()).Trim())) { return(Ok(new { mark = "2", msg = "内容为空!" })); } var headerStr = Request.Headers["Authorization"]; var jwtHelper = new JWTHelper(_configuration); var user = new UserInfo { UserId = jwtHelper.GetJWTUserData(headerStr) }; postInfo.Author = user; postInfo.Status = 1; postInfo.CreateDate = DateTime.Now; postInfo.UpdateDate = DateTime.Now; // 过滤 html 后的内容 //var pc = HtmlFillter.ReplaceHtmlToBlank(postInfo.PostContent); //描述 //postInfo.Description = pc.Length > 50 ? pc.Substring(0, 50) + " ..." : pc; postInfo.Description = HtmlFillter.ReplaceHtmlToBlank(postInfo.PostContent); var result = _postService.AddPostInfo(postInfo); if (result > 0) { return(Ok(new { mark = "1", postId = result, msg = "发布成功!" })); } return(Ok(new { mark = "2", msg = "处理失败!" })); } catch (Exception ex) { return(Ok(new { mark = "2", msg = ex.Message })); } }
public ActionResult AddReplyInfo([FromBody] ReplyInfoViewModel replyInfoViewModel) { try { #region 数据校验 if (replyInfoViewModel == null || string.IsNullOrEmpty(HtmlFillter.ReplaceHtmlToBlank(replyInfoViewModel.ReplyContent))) { return(Ok(new { mark = "2", msg = "回复内容为空!" })); } if (replyInfoViewModel.PostInfo == null) { return(Ok(new { mark = "2", msg = "帖子为空!" })); } if (replyInfoViewModel.PostInfo.PostId <= 0) { return(Ok(new { mark = "2", msg = "帖子为空!" })); } if (replyInfoViewModel.RepliedId != null) { if ((replyInfoViewModel.RepliedId <= 0 && replyInfoViewModel.RepliedUserInfo == null) || (replyInfoViewModel.RepliedUserInfo.UserId <= 0 && replyInfoViewModel.RepliedId > 0)) { return(Ok(new { mark = "2", msg = "用户回复关系异常!" })); } replyInfoViewModel.RepliedUserId = replyInfoViewModel.RepliedUserInfo.UserId; } #endregion #region 根据token获得用户ID var headerStr = Request.Headers["Authorization"]; var jwtHelper = new JWTHelper(_configuration); var user = new UserInfo { UserId = jwtHelper.GetJWTUserData(headerStr) }; #endregion replyInfoViewModel.ReplyUser = user; replyInfoViewModel.ReplyDate = DateTime.Now; replyInfoViewModel.UpdateDate = DateTime.Now; var result = _replyService.AddReplyInfo(replyInfoViewModel); if (result > 0) { return(Ok(new { mark = "1", msg = "成功!" })); } return(Ok(new { mark = "2", msg = "处理失败!" })); } catch (Exception ex) { return(Ok(new { mark = "2", msg = ex.Message })); } }