Files
FACULTATE-HEALTHCARE_MANAGER/backend/Infrastructure/Services/PostgreSQL/BasePostgreSQLRepository.cs
T
ElenitaMLG 55eaa0d53a Backend Pacients, Doctors and MedicalHistory endpoints
- 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
2024-04-07 00:23:13 +03:00

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();
}
}