refactored error handling
This commit is contained in:
1 parent
de94725885
commit
ec91488f9a
2 files changed
+8
-12
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user