Esempio n. 1
0
        public async Task <ApiResult <PagedResult <CourseVm> > > GetAllPagingByDay(GetCourseByDayRequest request)
        {
            var user = await _userManager.FindByIdAsync(request.Id_User.ToString());

            var query = from c in _context.Courses
                        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 c.SchoolYear == request.SchoolYear && c.Semester == request.Semester
                        select new { c, t, s };

            if (user.Type == "teacher")
            {
                query = query.Where(x => x.t.Id == request.Id_User);
            }
            //filter
            if (!string.IsNullOrEmpty(request.Keyword))
            {
                query = query.Where(x => x.c.Name.Contains(request.Keyword));
            }

            //Paging
            int totalRow = await query.CountAsync();

            var data = await query
                       .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,
                Semester    = x.c.Semester,
                SchoolYear  = x.c.SchoolYear,
                DateCreate  = x.c.DateCreate,
                DateUpdate  = x.c.DateUpdate,
            }).ToListAsync();

            var pagedResult = new PagedResult <CourseVm>()
            {
                TotalRecords = totalRow,
                PageSize     = totalRow,
                PageIndex    = 1,
                Items        = data
            };

            return(new ApiSuccessResult <PagedResult <CourseVm> >(pagedResult));
        }
Esempio n. 2
0
        public async Task <IActionResult> PagingBySemeter([FromQuery] GetCourseByDayRequest request)
        {
            var courses = await _courseService.GetAllPagingByDay(request);

            return(Ok(courses));
        }