ContractRepository.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. .Include(x => x.WorkingDays)
  23. .FirstOrDefaultAsync(x => x.Id == id);
  24. }
  25. public async Task<Tuple<IQueryable<Contract>, int>> GetAllWithChildrenAsync()
  26. {
  27. var query = dbSet//.Include(x => x.ContractUsers)
  28. .AsQueryable();
  29. var total = await query.CountAsync();
  30. return new Tuple<IQueryable<Contract>, int>(query, total);
  31. }
  32. }
  33. }