using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Domain.Models.MetaData; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; namespace BMA.EHR.Application.Repositories.MetaData { public class HolidayRepository : GenericRepository { #region " Fields " private readonly IApplicationDBContext _dbContext; private readonly IHttpContextAccessor _httpContextAccessor; #endregion #region " Costructor and Destructor " public HolidayRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor) { _dbContext = dbContext; _httpContextAccessor = httpContextAccessor; } #endregion #region " Methods " public async Task GetHolidayAsync(DateTime date, string category = "NORMAL") { var data = await _dbContext.Set().AsQueryable() .Where(x => x.Category == category) .Where(x => x.HolidayDate.Date == date.Date) .Select(x => x.Name) .FirstOrDefaultAsync(); return data ?? string.Empty; } public async Task> GetHolidayAsync(DateTime startDate, DateTime endDate, string category = "NORMAL") { var data = await _dbContext.Set().AsQueryable() .Where(x => x.Category == category) .Where(x => x.HolidayDate.Date >= startDate && x.HolidayDate.Date <= endDate) .Select(x => x.HolidayDate.Date) .ToListAsync(); return data; } public async Task GetHolidayCountAsync(DateTime startDate, DateTime endDate, string category = "NORMAL") { var data = await _dbContext.Set().AsQueryable() .Where(x => x.Category == category) .Where(x => x.HolidayDate.Date >= startDate && x.HolidayDate.Date <= endDate) .CountAsync(); return data; } public List GetWeekEnd(DateTime startDate, DateTime endDate, string category = "NORMAL") { var dates = new List(); for (DateTime i = startDate; i <= endDate; i = i.AddDays(1)) { dates.Add(i); } if (category == "NORMAL") return dates.Where(d => d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday).ToList(); else return dates.Where(d => d.DayOfWeek == DayOfWeek.Sunday).ToList(); } public int GetWeekEndCount(DateTime startDate, DateTime endDate, string category = "NORMAL") { var dates = new List(); for (DateTime i = startDate; i <= endDate; i = i.AddDays(1)) { dates.Add(i); } var count = 0; if (category == "NORMAL") count = dates.Where(d => d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Sunday).Count(); else count = dates.Where(d => d.DayOfWeek == DayOfWeek.Sunday).Count(); return count; } #endregion } }