Skip to content

Commit 5dae181

Browse files
committed
disallow project delete when there are existing bugs
1 parent 0fb9997 commit 5dae181

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

BugLab.Business/CommandHandlers/Projects/DeleteProjectHandler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using BugLab.Business.Commands.Projects;
22
using BugLab.Business.Helpers;
33
using BugLab.Data;
4+
using BugLab.Shared.Enums;
45
using MediatR;
56
using Microsoft.EntityFrameworkCore;
7+
using System;
8+
using System.Linq;
69
using System.Threading;
710
using System.Threading.Tasks;
811

@@ -22,6 +25,11 @@ public async Task<Unit> Handle(DeleteProjectCommand request, CancellationToken c
2225
var project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken);
2326
Guard.NotFound(project, nameof(project), request.Id);
2427

28+
if (await _context.Bugs.AnyAsync(b => b.ProjectId == project.Id && b.Status != BugStatus.Resolved, cancellationToken))
29+
{
30+
throw new InvalidOperationException("remove or resolve existing bugs before deletion");
31+
}
32+
2533
_context.Projects.Remove(project);
2634
await _context.SaveChangesAsync(cancellationToken);
2735

0 commit comments

Comments
 (0)