OrderAllocationRepository.cs 1.9 KB

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