- added for Pacients: POST: /register POST: /login POST: /reset_password PUT: /profile DELETE: /profile - added for Doctors: POST: /register POST: /login POST: /reset_password PUT: /profile DELETE: /profile - added for MedicalHistories: POST: /:id (only by pacient) - done GET: /:id (only by pacient) - done PUT: /:id (only by doctor) - done PUT /grand_access - TODO
44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Infrastructure.Services.PostgreSQL;
|
|
|
|
public class BasePostgreSQLRepository<T> where T : class
|
|
{
|
|
protected readonly HealthcareManagerDatabase _context;
|
|
|
|
public BasePostgreSQLRepository(HealthcareManagerDatabase context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<T> GetByIdAsync(Guid id)
|
|
{
|
|
return await _context.Set<T>().FindAsync(id);
|
|
}
|
|
|
|
public async Task<IEnumerable<T>> GetAllAsync()
|
|
{
|
|
return await _context.Set<T>().ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(T entity)
|
|
{
|
|
await _context.Set<T>().AddAsync(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task UpdateAsync(T entity)
|
|
{
|
|
_context.Set<T>().Attach(entity);
|
|
_context.Entry(entity).State = EntityState.Modified;
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(T entity)
|
|
{
|
|
_context.Set<T>().Remove(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|