public async Task <bool> DeleteArticle(int articleId) { //文章Id必须要符合规范 if (articleId <= 0) { _logger.LogError("传入文章Id不合规范"); return(false); } //首先删除Redis缓存中的记录 string redisArticleKey = PostConsts.ArticleBaseKey + articleId; await _cacheManager .GetCache(PostConsts.RedisForArticleStore) .RemoveAsync(redisArticleKey); //获取指定文章 Article article = await _articleRepository .FirstOrDefaultAsync(a => a.Id == articleId); if (article != null) { //删除数据库中的记录 await _articleRepository.DeleteAsync(article); } //删除指定路径的存储在硬盘上的文章 await FileOperate.DeleteArticleAsync(article.ArticleUrl, _logger); //删除评论区 await _commentRepository.DeleteCommentAreaAsync(articleId.ToString()); return(true); }