44 lines
1.0 KiB
C#
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();
|
|
}
|
|
}
|
|
|
|
|
|
} |