ProjectRepository.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Microsoft.EntityFrameworkCore;
  2. using MTWorkHR.Core.Entities;
  3. using MTWorkHR.Core.IDto;
  4. using MTWorkHR.Infrastructure.Entities;
  5. using MTWorkHR.Infrastructure.DBContext;
  6. using MTWorkHR.Core.IRepositories;
  7. namespace MTWorkHR.Infrastructure.Repositories
  8. {
  9. public class ProjectRepository : Repository<Project>, IProjectRepository
  10. {
  11. private readonly DbSet<Project> dbSet;
  12. public ProjectRepository(HRDataContext context) : base(context)
  13. {
  14. dbSet = context.Set<Project>();
  15. }
  16. public async Task<Project> GetByIdWithAllChildren(long id)
  17. {
  18. return await dbSet
  19. .Include(x => x.ProjectTeams)
  20. .FirstOrDefaultAsync(x => x.Id == id);
  21. }
  22. public async Task<Tuple<IQueryable<Project>, int>> GetAllWithChildrenAsync()
  23. {
  24. var query = dbSet.Include(x => x.ProjectTeams).AsQueryable();
  25. var total = await query.CountAsync();
  26. return new Tuple<IQueryable<Project>, int>(query, total);
  27. }
  28. }
  29. }