UserTaskRepository.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 UserTaskRepository : Repository<UserTask>, IUserTaskRepository
  10. {
  11. private readonly DbSet<UserTask> dbSet;
  12. public UserTaskRepository(HRDataContext context) : base(context)
  13. {
  14. dbSet = context.Set<UserTask>();
  15. }
  16. public async Task<UserTask> GetByIdWithAllChildren(long id)
  17. {
  18. return await dbSet
  19. .Include(x => x.TaskAttachments).ThenInclude(a => a.AttachmentType)
  20. .Include(x => x.TaskHistories)
  21. .Include(x => x.TaskStatus)
  22. .Include(x => x.Project)
  23. .FirstOrDefaultAsync(x => x.Id == id);
  24. }
  25. public async Task<UserTask> GetByUserIdWithAllChildren(string userId)
  26. {
  27. return await dbSet
  28. .Include(x => x.TaskAttachments).ThenInclude(a => a.AttachmentType)
  29. .Include(x => x.TaskHistories)
  30. .Include(x => x.TaskStatus)
  31. .Include(x => x.Project)
  32. .FirstOrDefaultAsync(x => x.AssignedUserId == userId);
  33. }
  34. public async Task<Tuple<IQueryable<UserTask>, int>> GetAllWithChildrenAsync()
  35. {
  36. var query = dbSet.Include(x => x.Project).Include(x => x.TaskAttachments)
  37. .Include(x => x.TaskHistories).AsQueryable();
  38. var total = await query.CountAsync();
  39. return new Tuple<IQueryable<UserTask>, int>(query, total);
  40. }
  41. }
  42. }