public async Task <IActionResult> PagingByStudent([FromQuery] GetCourseByStudentRequest request) { var student = await _courseService.GetAllByIdStudent(request); if (student.IsSuccessed == false) { return(BadRequest(student)); } return(Ok(student)); }
public async Task <ApiResult <PagedResult <CourseVm> > > GetAllByIdStudent(GetCourseByStudentRequest request) { var query = from c in _context.Courses join rc in _context.RegisterCourses on c.Id_Course equals rc.Id_Course join t in _context.Teachers on c.Id_Teacher equals t.Id join s in _context.Subjects on c.Id_Subject equals s.Id_Subject where rc.Id_Student == request.Id select new { c, t, s }; //filter if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(x => x.c.Name.Contains(request.Keyword) || x.s.Name.Contains(request.Keyword)); } //Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new CourseVm() { Id_Course = x.c.Id_Course, Name = x.c.Name, NameTeacher = x.t.FullName, NameSubject = x.s.Name, DateBegin = x.c.DateBegin, DateEnd = x.c.DateEnd, SchoolYear = x.c.SchoolYear, Semester = x.c.Semester, DateCreate = x.c.DateCreate, DateUpdate = x.c.DateUpdate, }).ToListAsync(); var pagedResult = new PagedResult <CourseVm>() { TotalRecords = totalRow, PageSize = request.PageSize, PageIndex = request.PageIndex, Items = data }; return(new ApiSuccessResult <PagedResult <CourseVm> >(pagedResult)); }
//[Authorize(Roles = "teacher")] public async Task <IActionResult> PagingByTeacher([FromQuery] GetCourseByStudentRequest request) { var courses = await _courseService.GetAllByIdTeacher(request); return(Ok(courses)); }