Files
probearbeit/api/Repositories/PersonRepository.cs
T
2026-08-30 16:54:12 +02:00

44 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using api.Data;
using api.Domain;
using api.Repositories;
public class PersonRepository(AppDbContext context) : IPersonRepository
{
private readonly AppDbContext _context = context;
public async Task<IEnumerable<Person>> GetAllAsync()
{
return await _context.Persons.ToListAsync();
}
public async Task AddAsync(Person person)
{
await _context.Persons.AddAsync(person);
await _context.SaveChangesAsync();
}
public async Task<Person> GetByUsernameAsync(string username)
{
return await _context.Persons.FindAsync(username);
}
public async Task UpdateAsync(Person person)
{
_context.Persons.Update(person);
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(string username)
{
Person person = await _context.Persons.FindAsync(username);
if (person != null)
{
_context.Persons.Remove(person);
await _context.SaveChangesAsync();
}
}
}