public async Task DeleteAsync(long id) { var exist = await _categoryRepo.Select.AnyAsync(s => s.Id == id && !s.IsDeleted); if (!exist) { throw new KnownException("没有找到该账单分类信息", ServiceResultCode.NotFound); } await _categoryRepo.DeleteAsync(id); }
public async Task <ServiceResult> DeleteAsync(long id) { var exist = await _categoryRepo.Select.AnyAsync(c => c.Id == id); if (!exist) { return(await Task.FromResult(ServiceResult.Failed($"Id:{id} 的文章分类不存在"))); } var articleIds = await _articleRepo.Select.Where(a => a.CategoryId == id).ToListAsync(a => a.Id); // 删除相关的文章信息 await _articleRepo.DeleteAsync(a => articleIds.Contains(a.Id)); // 删除相关文章的内容信息 await _articleContentRepo.DeleteAsync(a => articleIds.Contains(a.ArticleId)); // 删除文章分类 await _categoryRepo.DeleteAsync(id); return(await Task.FromResult(ServiceResult.Successed("删除文章分类成功"))); }