Exemplo n.º 1
0
        public ApplicantsAndLessonsViewModel Search(ApplicantSerachViewModel searchModel, int?page)
        {
            var lessons = _dbContext.Lessons
                          .Include(l => l.Teacher)
                          .Include(l => l.Technology);

            var teachers     = _dbContext.Teachers;
            var technologies = _dbContext.Technologies;

            var applicants = _dbContext.GetApplicants();

            List <ApplicantInfoViewModel> applicantsIVM = applicants
                                                          .Filter(searchModel)
                                                          .GetAllApplicantIVM();

            int pageSize            = 15;
            var paginatedApplicants = PaginatedList <ApplicantInfoViewModel> .Create(
                applicantsIVM, page ?? 1, pageSize);

            ApplicantsAndLessonsViewModel model = ApplicantMapper.Mapping(
                paginatedApplicants, lessons, teachers, technologies,
                searchModel.FirstName, searchModel.LastName, searchModel.LessonId,
                searchModel.TeacherId, searchModel.TechnologyId, page);

            return(model);
        }
        public static IQueryable <Applicant> Filter(this IQueryable <Applicant> applicants,
                                                    ApplicantSerachViewModel serachModel)
        {
            if (!string.IsNullOrEmpty(serachModel.FirstName))
            {
                applicants = applicants
                             .Where(a => a.FirstName.Contains(serachModel.FirstName));
            }
            if (!string.IsNullOrEmpty(serachModel.LastName))
            {
                applicants = applicants
                             .Where(a => a.LastName.Contains(serachModel.LastName));
            }
            if (serachModel.LessonId != 0)
            {
                applicants = applicants
                             .Where(a => a.Lesson.Id == serachModel.LessonId);
            }
            if (serachModel.TeacherId != 0)
            {
                applicants = applicants
                             .Where(a => a.Lesson.TeacherId == serachModel.TeacherId);
            }
            if (serachModel.TechnologyId != 0)
            {
                applicants = applicants
                             .Where(a => a.Lesson.TechnologyId == serachModel.TechnologyId);
            }

            return(applicants);
        }
        public IActionResult AllApplicants()
        {
            ApplicantSerachViewModel searchModel =
                ApplicantMapper.Mapping(string.Empty, string.Empty, 0, 0, 0);

            ApplicantsAndLessonsViewModel model = Search(searchModel, 1);

            return(View(model));
        }
Exemplo n.º 4
0
        public IActionResult AllApplicants(string firstName, string lastName,
                                           int lessonId, int teacherId, int technologyId, int?page)
        {
            ApplicantSerachViewModel searchModel =
                ApplicantMapper.Mapping(firstName, lastName, lessonId, teacherId, technologyId);

            ApplicantsAndLessonsViewModel model = Search(searchModel, page);

            return(View(model));
        }
        public IActionResult Change(string firstName, string lastName,
                                    int lessonId, int teacherId, int technologyId, int page)
        {
            ApplicantSerachViewModel searchModel =
                ApplicantMapper.Mapping(firstName, lastName, lessonId, teacherId, technologyId);

            ApplicantsAndLessonsViewModel model = Search(searchModel, page);

            return(View("_ApplicantTablePartial", model));
        }