Exemplo n.º 1
0
        public IEnumerable <StudentDTO> SearchByProgress(IEnumerable <StudentDTO> studentDtos, string searchProgress)
        {
            List <EducationProcessDTO> educations = educationService.Get().Where(s => s.SubjectResult < 60).Distinct().ToList();
            List <int> idStudents = new List <int>();

            foreach (var education in educations)
            {
                idStudents.Add(education.IdStudent);
            }
            idStudents = idStudents.Distinct().ToList();

            List <StudentDTO> students = new List <StudentDTO>();

            foreach (var id in idStudents)
            {
                students.Add(GetStudent(id));
            }
            IEnumerable <StudentDTO> studentNoSuccess = studentDtos, studentSuccess = studentDtos;

            foreach (var student in studentDtos)
            {
                if (students.FirstOrDefault(s => s.Id == student.Id) == null)
                {
                    studentNoSuccess = studentNoSuccess.Where(element => element.Id != student.Id);
                }
            }
            foreach (var student in studentDtos)
            {
                if (studentNoSuccess.FirstOrDefault(s => s.Id == student.Id) != null)
                {
                    studentSuccess = studentSuccess.Where(s => s.Id != student.Id);
                }
            }

            if (searchProgress == "Успішні")
            {
                return(studentSuccess);
            }
            else if (searchProgress == "Неуспішні")
            {
                return(studentNoSuccess);
            }
            return(studentDtos);
        }
Exemplo n.º 2
0
        public ActionResult ShowStudent(string searchName, string searchGroup, string searchStudentAvg, string searchProgress, string searchSubject)
        {
            ViewBag.groups   = groupService.Get();
            ViewBag.subjects = subjectService.Get();

            IEnumerable <StudentDTO> studentDtos = studentService.Get().OrderBy(s => s.Name);
            List <double>            studentAvgs = new List <double>();

            foreach (var student in studentDtos)
            {
                studentAvgs.Add(student.StudentAvg);
            }
            studentAvgs = studentAvgs.Distinct().ToList();
            studentAvgs.Sort();
            ViewBag.studentAvgs = studentAvgs;

            if (!String.IsNullOrEmpty(searchName))
            {
                studentDtos = studentService.SearchByName(studentDtos, searchName);
            }
            if (!String.IsNullOrEmpty(searchGroup))
            {
                int groupId = groupService.Get().Where(g => g.Name == searchGroup).FirstOrDefault().Id;
                studentDtos = studentService.SearchByGroup(studentDtos, groupId);
            }
            if (!String.IsNullOrEmpty(searchStudentAvg) && (searchStudentAvg != "Всі"))
            {
                studentDtos = studentService.SearchByStudentAvg(studentDtos, searchStudentAvg);
            }
            if (!String.IsNullOrEmpty(searchProgress))
            {
                studentDtos = studentService.SearchByProgress(studentDtos, searchProgress);
            }
            if (!String.IsNullOrEmpty(searchSubject))
            {
                int subjectId = subjectService.Get().Where(s => s.Name == searchSubject).FirstOrDefault().Id;
                IEnumerable <EducationProcessDTO> educationDtos = educationService.Get().Where(s => s.IdSubject == subjectId);
                studentDtos = studentService.SearchBySubject(studentDtos, educationDtos);
            }

            var             mapper     = new MapperConfiguration(cfg => cfg.CreateMap <StudentDTO, StudentViewModel>()).CreateMapper();
            var             students   = mapper.Map <IEnumerable <StudentDTO>, List <StudentViewModel> >(studentDtos);
            List <GroupDTO> groupsList = new List <GroupDTO>();

            foreach (var item in studentDtos)
            {
                groupsList.Add(groupService.GetGroup(item.IdGroup));
            }
            Dictionary <StudentViewModel, GroupDTO> studentGroup = new Dictionary <StudentViewModel, GroupDTO>();

            foreach (StudentViewModel studentVM in students)
            {
                studentGroup.Add(studentVM, groupsList.FirstOrDefault(g => g.Id == studentVM.IdGroup));
            }

            if (studentGroup.Count() == 0)
            {
                ViewBag.message = "Пошук не дав результатів";
            }
            return(View(studentGroup));
        }