Compare commits
No commits in common. "4b63e1a1d059ac93f644c1bb1e2968953dbb92a9" and "77d5d388bc9bc5f7091f20b09fe8a09977efe275" have entirely different histories.
4b63e1a1d0
...
77d5d388bc
@ -1,15 +0,0 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace ldap_cesi.Repository.Services;
|
||||
|
||||
public interface IRepositoryBase<TEntity> where TEntity : class
|
||||
{
|
||||
Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
|
||||
Task<TEntity> GetByIdAsync<TId>(TId id, CancellationToken cancellationToken = default) where TId : notnull;
|
||||
Task<List<TEntity>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||
Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||
Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||
Task<TEntity?> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using ldap_cesi.Entities;
|
||||
|
||||
namespace ldap_cesi.Repository.Services;
|
||||
|
||||
public interface IRepositoryRole : IRepositoryBase<Role>
|
||||
{
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using ldap_cesi.Entities;
|
||||
|
||||
namespace ldap_cesi.Repository.Services;
|
||||
|
||||
public interface IRepositorySalarie : IRepositoryBase<Salarie>
|
||||
{
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using ldap_cesi.Entities;
|
||||
|
||||
namespace ldap_cesi.Repository.Services;
|
||||
|
||||
public interface IRepositoryService : IRepositoryBase<Service>
|
||||
{
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using ldap_cesi.Entities;
|
||||
|
||||
namespace ldap_cesi.Repository.Services;
|
||||
|
||||
public interface IRepositorySite : IRepositoryBase<Site>
|
||||
{
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using ldap_cesi.Entities;
|
||||
|
||||
namespace ldap_cesi.Repository.Services;
|
||||
|
||||
public interface IRepositoryUtilisateur : IRepositoryBase<Utilisateur>
|
||||
{
|
||||
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
using System.Linq.Expressions;
|
||||
using ldap_cesi.Context;
|
||||
using ldap_cesi.Repository.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ldap_cesi.Repository;
|
||||
|
||||
public class RepositoryBase<TEntity> : IRepositoryBase<TEntity> where TEntity : class
|
||||
{
|
||||
protected readonly PgContext _context;
|
||||
|
||||
public RepositoryBase(PgContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
public virtual async Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Set<TEntity>().Add(entity);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
return entity;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Erreur pendant l'ajout de l'entité.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Set<TEntity>().AnyAsync(predicate, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public virtual async Task<List<TEntity>> GetAllAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _context.Set<TEntity>().ToListAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Erreur pendant la récupérations des entités.", ex);
|
||||
}
|
||||
}
|
||||
public virtual async Task<TEntity?> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Set<TEntity>().FirstOrDefaultAsync(predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public virtual async Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Set<TEntity>().Update(entity);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Erreur pendant la mis à jour", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<TEntity?> GetByIdAsync<TId>(TId id, CancellationToken cancellationToken = default) where TId : notnull
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _context.FindAsync<TEntity>(id, cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Erreur lors de la récupération avec l'id : {id}.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task DeleteAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Set<TEntity>().Remove(entity);
|
||||
await SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Erreur pendant la suppression de l'entité", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Erreur pendant le sauvegarde en base de donnése.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<List<TEntity>> ListAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _context.Set<TEntity>().ToListAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Erreur qui concerne le listing des entités", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using ldap_cesi.Context;
|
||||
using ldap_cesi.Entities;
|
||||
using ldap_cesi.Repository.Services;
|
||||
|
||||
namespace ldap_cesi.Repository;
|
||||
|
||||
public class RoleRepository : RepositoryBase<Role>, IRepositoryRole
|
||||
{
|
||||
public RoleRepository(PgContext context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using ldap_cesi.Context;
|
||||
using ldap_cesi.Entities;
|
||||
using ldap_cesi.Repository.Services;
|
||||
|
||||
namespace ldap_cesi.Repository;
|
||||
|
||||
public class SalarieRepository : RepositoryBase<Salarie>, IRepositorySalarie
|
||||
{
|
||||
public SalarieRepository(PgContext context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using ldap_cesi.Context;
|
||||
using ldap_cesi.Entities;
|
||||
using ldap_cesi.Repository.Services;
|
||||
|
||||
namespace ldap_cesi.Repository;
|
||||
|
||||
public class ServiceRepository : RepositoryBase<Service>, IRepositoryService
|
||||
{
|
||||
public ServiceRepository(PgContext context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using ldap_cesi.Context;
|
||||
using ldap_cesi.Entities;
|
||||
using ldap_cesi.Repository.Services;
|
||||
|
||||
namespace ldap_cesi.Repository;
|
||||
|
||||
public class SiteRepository : RepositoryBase<Site>, IRepositorySite
|
||||
{
|
||||
public SiteRepository(PgContext context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using ldap_cesi.Context;
|
||||
using ldap_cesi.Entities;
|
||||
using ldap_cesi.Repository.Services;
|
||||
|
||||
namespace ldap_cesi.Repository;
|
||||
|
||||
public class UtilisateurRepository : RepositoryBase<Utilisateur>, IRepositoryUtilisateur
|
||||
{
|
||||
public UtilisateurRepository(PgContext context) : base(context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Entities\" />
|
||||
<Folder Include="Mapper\" />
|
||||
<Folder Include="Repository\" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user