1
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Yes.Application.Admins.Articles
|
||||
private readonly BlogDbContext _db = db;
|
||||
public async Task<bool> IsSlugInUse(string slug)
|
||||
{
|
||||
return await _db.Articles.AnyAsync(x => x.Slug == slug);
|
||||
return await _db.Articles.AnyAsync(x => x.Slug == slug && x.Status!= ArticleStatusEnum.Deleted);
|
||||
}
|
||||
|
||||
public async Task<string> CreateUniqueSlug()
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
public async Task<DeleteArticleCommandResponse> Handle(DeleteArticleCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var article = await _db.Articles.FindAsync(request.Id);
|
||||
if (article != null)
|
||||
if (article != null && article.Status!= ArticleStatusEnum.Deleted)
|
||||
{
|
||||
var identityUser = await _db.Users.FindAsync(_identity.Id);
|
||||
if (identityUser == null)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
private readonly BlogDbContext _db = db;
|
||||
public async Task<List<GetLatestArticlesQueryResponse>> Handle(GetLatestArticlesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _db.Articles.AsNoTracking().Where(x=>x.Type==ArticleTypeEnum.Article x.Status != ArticleStatusEnum.Deleted).OrderByDescending(x => x.Id).Select(article =>
|
||||
var query = _db.Articles.AsNoTracking().Where(x=>x.Type==ArticleTypeEnum.Article && x.Status != ArticleStatusEnum.Deleted).OrderByDescending(x => x.Id).Select(article =>
|
||||
new GetLatestArticlesQueryResponse(
|
||||
article.Id,
|
||||
article.Title,
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
var categoryObject = ValueObject<CategoryEntity>.Create(request.CategoryId, category);
|
||||
|
||||
var article = await _db.Articles.FindAsync(request.Id);
|
||||
if (article == null)
|
||||
if (article == null|| article.Status == ArticleStatusEnum.Deleted)
|
||||
{
|
||||
throw new ArticleNotExistsException(request.Id);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
var categoryObject = ValueObject<CategoryEntity>.Create(request.CategoryId, category);
|
||||
|
||||
var article = await _db.Articles.FindAsync(request.Id);
|
||||
if (article == null)
|
||||
if (article == null || article.Status == ArticleStatusEnum.Deleted)
|
||||
{
|
||||
throw new ArticleNotExistsException(request.Id);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Yes.Application.Admins.Categories
|
||||
private readonly BlogDbContext _db = db;
|
||||
public async Task<bool> IsSlugInUse(string slug)
|
||||
{
|
||||
return await _db.Articles.AnyAsync(x => x.Slug == slug);
|
||||
return await _db.Articles.AnyAsync(x => x.Slug == slug && x.Status != ArticleStatusEnum.Deleted);
|
||||
}
|
||||
|
||||
public async Task<string> EnsureSlug()
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
||||
var hasArticlesInCategory = await _db.Articles.AnyAsync(x => x.CategoryId == request.Id, cancellationToken);
|
||||
var hasArticlesInCategory = await _db.Articles.AnyAsync(x => x.CategoryId == request.Id && x.Status!= ArticleStatusEnum.Deleted, cancellationToken);
|
||||
if (hasArticlesInCategory)
|
||||
{
|
||||
throw new DeleteCategoryException("分类下还有文章,无法删除!");
|
||||
|
||||
Reference in New Issue
Block a user