123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 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<OrderAllocation>, IOrderAllocationRepository
- {
- private readonly DbSet<OrderAllocation> dbSet;
- public OrderAllocationRepository(HRDataContext context) : base(context)
- {
- dbSet = context.Set<OrderAllocation>();
- }
- public async Task<OrderAllocation> GetByIdWithAllChildren(long id)
- {
- return await dbSet
- .Include(x => x.OrderType)
- .FirstOrDefaultAsync(x => x.Id == id);
- }
-
- public async Task<bool> 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<OrderAllocation> 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));
- }
- }
- }
|