public IActionResult ChangeStatus(ChangeStatusRequest model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

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

            return this.ApiResponse(result);
        }
Esempio n. 2
0
        public OperationResult ChangeStatus(ChangeStatusRequest model)
        {
            using (var conn = this.OpenConnection())
            {
                string sql = @"
UPDATE [Comment] SET [Status]=@Status
WHERE ID IN @IDs;

SELECT DISTINCT ArticleID FROM [Comment] WITH(NOLOCK)
WHERE ID IN @IDs;
";
                var para = new
                {
                    Status = model.Status,
                    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();
            }
        }