OrderAllocationRepository.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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, int period)
  23. {
  24. return await dbSet.AnyAsync(q => q.EmployeeId == userId
  25. && q.OrderTypeId == orderTypeId
  26. && q.Period == period);
  27. }
  28. public async Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long leaveTypeId, int period)
  29. {
  30. return await dbSet.FirstOrDefaultAsync(q => q.EmployeeId == userId
  31. && q.OrderTypeId == orderTypeId
  32. && q.Period == period
  33. && (leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId));
  34. }
  35. }
  36. }