finalizare 1.0

This commit is contained in:
andrei-mihnea-cerbu
2024-05-21 12:10:53 +03:00
parent f7795f7519
commit 1cc1d34003
11268 changed files with 2102399 additions and 10909 deletions
@@ -1,43 +1,38 @@
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Services.PostgreSQL;
public class BasePostgreSQLRepository<T> where T : class
public class BasePostgreSqlRepository<T>(HealthcareManagerDatabase context)
where T : class
{
protected readonly HealthcareManagerDatabase _context;
protected readonly HealthcareManagerDatabase Context = context;
public BasePostgreSQLRepository(HealthcareManagerDatabase context)
public async Task<T?> GetByIdAsync(Guid id, CancellationToken token)
{
_context = context;
return await Context.Set<T>().FindAsync(id, token);
}
public async Task<T?> GetByIdAsync(Guid id)
public async Task<IEnumerable<T>> GetAllAsync(CancellationToken token)
{
return await _context.Set<T>().FindAsync(id);
return await Context.Set<T>().ToListAsync(token);
}
public async Task<IEnumerable<T>> GetAllAsync()
public async Task AddAsync(T entity, CancellationToken token)
{
return await _context.Set<T>().ToListAsync();
await Context.Set<T>().AddAsync(entity, token);
await Context.SaveChangesAsync(token);
}
public async Task AddAsync(T entity)
public async Task UpdateAsync(T entity, CancellationToken token)
{
await _context.Set<T>().AddAsync(entity);
await _context.SaveChangesAsync();
Context.Set<T>().Attach(entity);
Context.Entry(entity).State = EntityState.Modified;
await Context.SaveChangesAsync(token);
}
public async Task UpdateAsync(T entity)
public async Task DeleteAsync(T entity, CancellationToken token)
{
_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();
Context.Set<T>().Remove(entity);
await Context.SaveChangesAsync(token);
}
}