ContractRepository.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 ContractRepository : Repository<Contract>, IContractRepository
  10. {
  11. private readonly DbSet<Contract> dbSet;
  12. public ContractRepository(HRDataContext context) : base(context)
  13. {
  14. dbSet = context.Set<Contract>();
  15. }
  16. public async Task<Contract> GetByIdWithAllChildren(long id)
  17. {
  18. return await dbSet
  19. .Include(x => x.ContractTasks)
  20. .Include(x => x.FixedAllowances)
  21. .Include(x => x.ProjectStages)
  22. .FirstOrDefaultAsync(x => x.Id == id);
  23. }
  24. public async Task<Tuple<IQueryable<Contract>, int>> GetAllWithChildrenAsync()
  25. {
  26. var query = dbSet//.Include(x => x.ContractUsers)
  27. .AsQueryable();
  28. var total = await query.CountAsync();
  29. return new Tuple<IQueryable<Contract>, int>(query, total);
  30. }
  31. }
  32. }