public IActionResult Delete(DeleteCommentRequest model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var result = this.CommentService.Delete(model);

            return this.ApiResponse(result);
        }
Esempio n. 2
0
        public OperationResult Delete(DeleteCommentRequest model)
        {
            using (var conn = this.OpenConnection())
            {
                string sql = @"
SELECT DISTINCT ArticleID 
FROM [Comment] WITH(NOLOCK)
WHERE ID IN @IDs;

UPDATE [Comment]
SET ReplyTo=NULL
WHERE ReplyTo IN @IDs;

DELETE FROM [Comment]
WHERE ID IN @IDs;
";
                var para = new
                {
                    IDs = model.CommentIDList
                };

                var articleIDList = conn.Query<int>(sql, para).ToList();

                if (articleIDList.Count == 0)
                {
                    return OperationResult.ErrorResult("不存在的评论");
                }

                foreach (var articleID in articleIDList)
                {
                    string cacheKey = Helpers.CacheKeyHelper.GetArticleCommentsCacheKey(articleID);
                    this.Cache.Remove(cacheKey);
                }

                return OperationResult.SuccessResult();
            }
        }