Пример #1
0
        public async Task <IActionResult> Index(string searchTerm = "", int page = 1)
        {
            if (searchTerm == null)
            {
                searchTerm = string.Empty;
            }

            if (!Regex.IsMatch(searchTerm, @"^\s*[A-Za-z0-9.-_]*\s*$"))
            {
                searchTerm = string.Empty;
                TempData.AddErrorMessage("Invalid search characters provided.");
            }
            var teacherId = userManager.GetUserId(HttpContext.User);
            var students  = await this.teacherStudentServeice.AllAsync(teacherId, searchTerm, page);

            var teacherCourses = teacherCourseService
                                 .AllAsync(TeacherId(), "", 1).Result
                                 .Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.Id.ToString()
            })
                                 .ToList();

            this.HttpContext.Request.QueryString.Add("searchTerm", searchTerm);

            return(View(new TeacherStudentsViewModel
            {
                Courses = teacherCourses,
                TotalItems = await teacherStudentServeice.TotalAsync(searchTerm),
                Students = students,
                SearchTerm = searchTerm,
                CurrentPage = page
            }));
        }
Пример #2
0
        // GET Index
        public async Task <IActionResult> Index(string searchTerm = "", int page = 1)
        {
            if (searchTerm == null)
            {
                searchTerm = string.Empty;
            }

            if (!Regex.IsMatch(searchTerm, @"^\s*[A-Za-z0-9.-_]*\s*$"))
            {
                searchTerm = string.Empty;
                TempData.AddErrorMessage("Invalid search characters provided.");
            }

            var courses = await teacherCourseService.AllAsync(TeacherId(), searchTerm, page);

            var coursesListing = new TeacherCoursesListingViewModel
            {
                TeacherCourses = courses,
                CurrentPage    = page,
                SearchTerm     = searchTerm,
                TotalItems     = await teacherCourseService.TotalAsync(TeacherId(), searchTerm)
            };

            return(View(coursesListing));
        }