OrderAllocationRepository.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Microsoft.EntityFrameworkCore;
  2. using MTWorkHR.Core.Entities;
  3. using MTWorkHR.Core.IDto;
  4. using MTWorkHR.Core.IRepositories;
  5. using MTWorkHR.Infrastructure.Entities;
  6. using MTWorkHR.Infrastructure.DBContext;
  7. namespace MTWorkHR.Infrastructure.Repositories
  8. {
  9. public class OrderAllocationRepository : Repository<OrderAllocation>, IOrderAllocationRepository
  10. {
  11. private readonly DbSet<OrderAllocation> dbSet;
  12. public OrderAllocationRepository(HRDataContext context) : base(context)
  13. {
  14. dbSet = context.Set<OrderAllocation>();
  15. }
  16. public async Task<OrderAllocation> GetByIdWithAllChildren(long id)
  17. {
  18. return await dbSet
  19. .Include(x => x.OrderType)
  20. .FirstOrDefaultAsync(x => x.Id == id);
  21. }
  22. public async Task<bool> AllocationExists(string userId, long orderTypeId, long? leaveTypeId, int period)
  23. {
  24. return await dbSet.AnyAsync(q => q.EmployeeId == userId
  25. && q.OrderTypeId == orderTypeId
  26. && q.Period == period
  27. && (!leaveTypeId.HasValue || leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId));
  28. }
  29. public async Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long? leaveTypeId, int period)
  30. {
  31. return await dbSet.FirstOrDefaultAsync(q => q.EmployeeId == userId
  32. && q.OrderTypeId == orderTypeId
  33. && q.Period == period
  34. && (!leaveTypeId.HasValue || leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId));
  35. }
  36. }
  37. }