public async Task <PageResultDto <StudentDto> > GetAllPaging([FromQuery] GetStudentPagingRequestDto request) { var result = await _studentService.GetAllPaging(request); return(result); }
/// <summary> /// Tìm kiếm và phân trang danh sách học sinh /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <PageResultDto <StudentDto> > GetAllPaging(GetStudentPagingRequestDto request) { var query = from s in _context.Students where s.IsDeleted == false join p in _context.AppUsers on s.ParentId equals p.Id join b in _context.Buses on s.BusId equals b.Id join stp in _context.Stops on s.StopPickId equals stp.Id join std in _context.Stops on s.StopDropId equals std.Id select new { s, p, b, stp, std }; // Filter if (!string.IsNullOrEmpty(request.Name)) { query = query.Where(x => x.s.Name.Contains(request.Name)); } if (!string.IsNullOrEmpty(request.StopName)) { query = query.Where(x => x.stp.Name.Contains(request.StopName)); } if (!string.IsNullOrEmpty(request.BusName)) { query = query.Where(x => x.b.Name.Contains(request.BusName)); } if (request.StudentStatus != null) { query = query.Where(x => x.s.Status == (StudentStatus)request.StudentStatus); } // Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new StudentDto() { Id = x.s.Id, BusId = x.s.BusId, BusName = x.b.Name, ParentId = x.p.Id, ParentName = x.p.FullName, ClassOfStudent = x.s.ClassOfStudent, TeacherId = x.s.TeacherId, StopPickId = x.stp.Id, StopDropId = x.std.Id, StopPickName = x.stp.Name, StopDropName = x.std.Name, Name = x.s.Name, Address = x.s.Address, Dob = x.s.Dob, Email = x.s.Email, PhoneNumber = x.s.PhoneNumber, Status = (int)x.s.Status }).ToListAsync(); // Return var pageResult = new PageResultDto <StudentDto>() { StatusCode = ResponseCode.Success, Message = "Thực hiện thành công", TotalRecord = totalRow, Items = data }; return(pageResult); }