Consider the following method from a business layer.
public async Task<OneOf<NotFound, NotDeleted, Person>> DeletePersonAsync(int id, CancellationToken ct)
{
var person = await _db.People.FirstOrDefaultAsync(m => m.Id == id, ct);
if (person is null)
return new NotFound(id,"Person"); // ===> 404 NotFound
_db.People.Remove(person);
return await _db.SaveChangesAsync(ct) > 0
? person // ===> 200 OK
: new NotDeleted(id, "Person"); // ===> 409 Conflict ???
}
I am not sure whether SaveChangesAsync()
can return a non-positive integer in this case. Maybe because of race condition?
If it does really happen, what is the proper status code for it? 409
?