public async Task <IActionResult> PagingbyCourse([FromQuery] GetPagingByCourseRequest request) { var data = await _studentService.GetPagingByCourse(request); if (data.IsSuccessed == false) { return(BadRequest(data)); } return(Ok(data)); }
public async Task <ApiResult <PagedResult <StudentAttendanceVm> > > GetPagingByCourse(GetPagingByCourseRequest request) { var queryStudentAttdendace = from s in _context.Schedules join ha in _context.HistoryAttendances on s.Id_Schedule equals ha.Id_Schedule join d in _context.DetailHAs on ha.Id_HistoryAttendace equals d.Id_HistoryAttendance join st in _context.Students on d.Id_Student equals st.Id where s.Id_Course == request.Id_Course select new { s, d, st }; var queryStudent = from rc in _context.RegisterCourses join s in _context.Students on rc.Id_Student equals s.Id join c in _context.Courses on rc.Id_Course equals c.Id_Course where rc.Id_Course == request.Id_Course select new { rc, s, c }; var queryAttendace = from ha in _context.Schedules where ha.Id_Course == request.Id_Course select new { ha }; int countDay = await queryAttendace.CountAsync(); if (!string.IsNullOrEmpty(request.Keyword)) { queryStudent = queryStudent.Where(x => x.s.FullName.Contains(request.Keyword)); } int totalRow = await queryStudent.CountAsync(); var data = await queryStudent.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new StudentAttendanceVm() { Id_Student = x.s.Id, Name = x.s.FullName, Email = x.s.Email, NameCource = x.c.Name, NumberDay = countDay, dayAttendances = queryStudentAttdendace.Where(y => y.st.Id == x.s.Id).Select(y => new DayAttendance() { Date = y.s.Date, id_Schedule = y.s.Id_Schedule }).ToList() }).ToListAsync(); var pagedResult = new PagedResult <StudentAttendanceVm>() { TotalRecords = totalRow, PageSize = request.PageSize, PageIndex = request.PageIndex, Items = data }; return(new ApiSuccessResult <PagedResult <StudentAttendanceVm> >(pagedResult)); }