OrderRequestRepository.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. using MTWorkHR.Core.Entities.User;
  8. namespace MTWorkHR.Infrastructure.Repositories
  9. {
  10. public class OrderRequestRepository : Repository<OrderRequest>, IOrderRequestRepository
  11. {
  12. private readonly DbSet<OrderRequest> dbSet;
  13. public OrderRequestRepository(HRDataContext context) : base(context)
  14. {
  15. dbSet = context.Set<OrderRequest>();
  16. }
  17. public async Task<OrderRequest> GetByIdWithAllChildren(long id)
  18. {
  19. return await dbSet
  20. .Include(x => x.OrderType)
  21. .FirstOrDefaultAsync(x => x.Id == id);
  22. }
  23. public async Task<Tuple<IQueryable<OrderRequest>, int>> GetAllWithChildrenAsync()
  24. {
  25. var query = dbSet.Include(x => x.OrderType).Include(x=> x.LeaveType).AsQueryable();
  26. var total = await query.CountAsync();
  27. return new Tuple<IQueryable<OrderRequest>, int>(query, total);
  28. }
  29. }
  30. }