AttendanceRepository.cs 1.1 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 AttendanceRepository : Repository<Attendance>, IAttendanceRepository
  10. {
  11. private readonly DbSet<Attendance> dbSet;
  12. public AttendanceRepository(HRDataContext context) : base(context)
  13. {
  14. dbSet = context.Set<Attendance>();
  15. }
  16. public async Task<Attendance> GetAttendanceByUserId(string userId, DateTime attendanceDate)
  17. {
  18. var result = await dbSet
  19. .FirstOrDefaultAsync(x => x.UserId == userId && x.AttendanceDate.Date == attendanceDate.Date && !x.CheckOutTime.HasValue);
  20. return result;
  21. }
  22. public async Task<Tuple<IQueryable<Attendance>, int>> GetAllWithChildrenAsync()
  23. {
  24. var query = dbSet.AsQueryable();
  25. var total = await query.CountAsync();
  26. return new Tuple<IQueryable<Attendance>, int>(query, total);
  27. }
  28. }
  29. }