6dcc911fc2
- Rename Template -> EmailTemplate, Provider -> EmailChannel, ProviderSettings -> EmailChannelSettings, ProviderType -> EmailChannelType, ProviderUsage -> EmailChannelUsage throughout all layers - Add Undefined = 0 to EmailChannelType enum for safe default handling - Remove SaveChangesAsync from EfRepository methods — repositories now only stage changes - Add SaveChangesAsync to IUnitOfWork and EfUnitOfWork - Add TransactionBehavior MediatR pipeline: wraps every handler in a transaction, saves and commits on success, rolls back on exception - Add MediatR package reference to Services project Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Linq.Expressions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace HrynCo.NotificationService.DAL.EF.Core;
|
|
|
|
internal abstract class EfRepository<TEntity>
|
|
where TEntity : class
|
|
{
|
|
protected NotificationDbContext DbContext { get; }
|
|
protected DbSet<TEntity> DbSet { get; }
|
|
|
|
protected EfRepository(NotificationDbContext dbContext)
|
|
{
|
|
DbContext = dbContext;
|
|
DbSet = dbContext.Set<TEntity>();
|
|
}
|
|
|
|
protected async Task AddAsync(TEntity entity, CancellationToken ct = default)
|
|
{
|
|
await DbSet.AddAsync(entity, ct);
|
|
}
|
|
|
|
protected async Task AddRangeAsync(IEnumerable<TEntity> entities, CancellationToken ct = default)
|
|
{
|
|
await DbSet.AddRangeAsync(entities, ct);
|
|
}
|
|
|
|
protected void Update(TEntity entity)
|
|
{
|
|
DbSet.Update(entity);
|
|
}
|
|
|
|
protected void Delete(TEntity entity)
|
|
{
|
|
DbSet.Remove(entity);
|
|
}
|
|
|
|
protected void DeleteRange(IEnumerable<TEntity> entities)
|
|
{
|
|
DbSet.RemoveRange(entities);
|
|
}
|
|
|
|
protected Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken ct = default) =>
|
|
DbSet.AnyAsync(predicate, ct);
|
|
} |