using Microsoft.EntityFrameworkCore; using MTWorkHR.Core.Entities; using MTWorkHR.Core.IDto; using MTWorkHR.Core.IRepositories; using MTWorkHR.Infrastructure.Entities; using MTWorkHR.Infrastructure.DBContext; namespace MTWorkHR.Infrastructure.Repositories { public class OrderAllocationRepository : Repository, IOrderAllocationRepository { private readonly DbSet dbSet; public OrderAllocationRepository(HRDataContext context) : base(context) { dbSet = context.Set(); } public async Task GetByIdWithAllChildren(long id) { return await dbSet .Include(x => x.OrderType) .FirstOrDefaultAsync(x => x.Id == id); } public async Task AllocationExists(string userId, long orderTypeId, long? leaveTypeId, int period) { return await dbSet.AnyAsync(q => q.EmployeeId == userId && q.OrderTypeId == orderTypeId && q.Period == period && (!leaveTypeId.HasValue || leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId)); } public async Task GetUserAllocations(string userId, long orderTypeId, long? leaveTypeId, int period) { return await dbSet.FirstOrDefaultAsync(q => q.EmployeeId == userId && q.OrderTypeId == orderTypeId && q.Period == period && (!leaveTypeId.HasValue || leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId)); } } }