นับวันหยุด ต้องตัดเสาร์ อาทิตย์ออก

This commit is contained in:
Suphonchai Phoonsawat 2026-05-12 12:02:45 +07:00
parent 91c479ef9e
commit 9263d880be

View file

@ -49,12 +49,16 @@ namespace BMA.EHR.Application.Repositories.MetaData
public async Task<int> GetHolidayCountAsync(DateTime startDate, DateTime endDate, string category = "NORMAL") public async Task<int> GetHolidayCountAsync(DateTime startDate, DateTime endDate, string category = "NORMAL")
{ {
var data = await _dbContext.Set<Holiday>().AsQueryable() var query = _dbContext.Set<Holiday>().AsQueryable()
.Where(x => x.Category == category) .Where(x => x.Category == category)
.Where(x => x.HolidayDate.Date >= startDate && x.HolidayDate.Date <= endDate) .Where(x => x.HolidayDate.Date >= startDate && x.HolidayDate.Date <= endDate);
.CountAsync();
return data; if (category == "NORMAL")
query = query.Where(x => x.HolidayDate.DayOfWeek != DayOfWeek.Saturday && x.HolidayDate.DayOfWeek != DayOfWeek.Sunday);
else
query = query.Where(x => x.HolidayDate.DayOfWeek != DayOfWeek.Sunday);
return await query.CountAsync();
} }
public List<DateTime> GetWeekEnd(DateTime startDate, DateTime endDate, string category = "NORMAL") public List<DateTime> GetWeekEnd(DateTime startDate, DateTime endDate, string category = "NORMAL")