refactored error handling

This commit is contained in:
marco committed 2026-08-31 13:54:35 +02:00
1 parent de94725885
commit ec91488f9a
2 files changed
+8 -12

No files matched your search

+3 -5
View File
@@ -20,7 +20,7 @@ public class PersonRepository(AppDbContext context) : IPersonRepository
public async Task<Person> GetByUsernameAsync(string username)
{
return await _context.Persons.FindAsync(username);
return await _context.Persons.FindAsync(username) ?? throw new KeyNotFoundException("User does not exist");
}
public async Task UpdateAsync(Person person)
{
@@ -30,14 +30,12 @@ public class PersonRepository(AppDbContext context) : IPersonRepository
public async Task DeleteAsync(string username)
{
Person person = await _context.Persons.FindAsync(username);
Person person = await _context.Persons.FindAsync(username) ?? throw new KeyNotFoundException("User does not exist");;
if (person != null)
{
_context.Persons.Remove(person);
await _context.SaveChangesAsync();
}
}