using BMA.EHR.Application.Common.Interfaces; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using System.Security.Claims; namespace BMA.EHR.Application.Repositories { public class GenericRepository : IGenericRepository where T : class { #region " Field " private readonly IApplicationDBContext _dbContext; private readonly DbSet _dbSet; private readonly IHttpContextAccessor _httpContextAccessor; #endregion #region " Constructor and Destructor " public GenericRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) { _dbContext = dbContext; _dbSet = _dbContext.Set(); _httpContextAccessor = httpContextAccessor; } #endregion #region " Properties " private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; #endregion #region " Methods " public async Task> GetAllAsync() { return await _dbSet.ToListAsync(); } public async Task GetByIdAsync(S id) { return await _dbSet.FindAsync(id); } #endregion } }