using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Domain.Models.HR; using BMA.EHR.Domain.Models.Notifications; using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; namespace BMA.EHR.Application.Repositories.MessageQueue { public class InboxRepository : GenericRepository { #region " Fields " private readonly IApplicationDBContext _dbContext; private readonly IHttpContextAccessor _httpContextAccessor; #endregion #region " Constructor and Destuctor " public InboxRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor) { _dbContext = dbContext; _httpContextAccessor = httpContextAccessor; } #endregion #region " Methods " public async Task> GetMyInboxAsync() { try { var profile = await _dbContext.Set() .FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!)); if (profile == null) { throw new Exception(GlobalMessages.DataNotFound); } var data = await _dbContext.Set() .Where(x => x.ReceiverUserId == profile.Id) .OrderByDescending(x => x.ReceiveDate) .ToListAsync(); return data; } catch { throw; } } #endregion } }