Example #1
0
        public IActionResult Index(NormalCommentModel model)
        {
            bool check = _postTokenManagerService.CheckAndDelPostToken(model.PostToken);

            if (check)
            {
                if (string.IsNullOrEmpty(model.CommentText) || string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Nikename))
                {
                    NormalCommentModel modelR = new NormalCommentModel()
                    {
                        PostToken = model.PostToken,
                        ServerMsg = "数据不完整"
                    };
                    return(View(modelR));
                }
                string        content       = _normalCommentService.ReplacementFilter(model.CommentText);
                NormalComment normalComment = new NormalComment()
                {
                    BlogId      = model.BlogId,
                    CreatedOn   = DateTime.Now,
                    CommentText = content,
                    Email       = model.Email,
                    Nikename    = model.Nikename,
                    IsDeleted   = false,
                    HomepageUrl = string.IsNullOrEmpty(model.HomepageUrl) ? "" : model.HomepageUrl,
                    PreIds      = ""
                };
                normalComment = _normalCommentService.CreateNormalComment(normalComment);
            }
            model = new NormalCommentModel()
            {
                ServerMsg = check?"提交成功":"Token丢失,提交失败,请尝试点击顶部留言连接"
            };
            return(View(model));
        }
Example #2
0
 public IActionResult AddApi(string nikename, string email, string homepageUrl, string commentText, int blogId)
 {
     if (string.IsNullOrEmpty(nikename) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(commentText))
     {
         return(new JsonResult("提交失败,格式可能不正确"));
     }
     else if (!email.Contains("@") && !email.Contains("."))
     {
         return(new JsonResult("提交失败,Email格式可能不正确"));
     }
     else
     {
         NormalComment normalComment = new NormalComment()
         {
             BlogId      = blogId,
             CreatedOn   = DateTime.Now,
             CommentText = commentText,
             Email       = email,
             Nikename    = nikename,
             IsDeleted   = false,
             HomepageUrl = homepageUrl == null ? "" : homepageUrl,
             PreIds      = ""
         };
         normalComment = _normalCommentService.CreateNormalComment(normalComment);
         string n = nikename;
         return(new JsonResult("Succuss"));
     }
 }
 public NormalComment CreateNormalComment(NormalComment normalComment)
 {
     _normalCommentRepository.Insert(normalComment);
     _mysqlContext.SaveChanges();
     _memoryCache.Remove(RBMemCacheKeys.NORMALCOMMENTKEY + normalComment.BlogId.ToString());
     _memoryCache.Remove(RBMemCacheKeys.NORMALCOMMENTKEY + "0");
     return(normalComment);
 }