Ejemplo n.º 1
0
        public async Task <IActionResult> Details(int id)
        {
            if (id < 1)
            {
                return(NotFound());
            }
            var education = await _educationService.Get(id);

            if (education.ResultStatus == ResultStatus.Error)
            {
                return(NotFound());
            }
            if (education.ResultStatus == ResultStatus.Success)
            {
                return(View(education.Data));
            }
            return(NotFound());
        }
        public async Task <IHttpActionResult> GetByUser(int userId = 0)
        {
            var currentUser = ApplicationContext.Current.CurrentUser;

            userId = userId == 0 ? currentUser.Id : userId;

            //first get the education
            var educationEntities = await _educationService.Get(x => x.UserId == userId, earlyLoad : x => x.School).ToListAsync();

            if (currentUser.Id == userId)
            {
                return(RespondSuccess(new {
                    Educations = educationEntities.Select(x => x.ToEntityModel())
                }));
            }

            return(RespondSuccess(new {
                Educations = educationEntities.Select(x => x.ToModel(_mediaService))
            }));
        }
Ejemplo n.º 3
0
        public IEnumerable <SubjectDTO> SearchByProgress(IEnumerable <SubjectDTO> subjectDtos, string searchProgress)
        {
            List <EducationDTO> educations = educationService.Get().Where(s => s.SubjectResult < 60).Distinct().ToList();
            List <int>          idSubjects = new List <int>();

            foreach (var education in educations)
            {
                idSubjects.Add(education.IdSubject);
            }
            idSubjects = idSubjects.Distinct().ToList();

            List <SubjectDTO> subjects = new List <SubjectDTO>();

            foreach (var id in idSubjects)
            {
                subjects.Add(GetSubject(id));
            }
            IEnumerable <SubjectDTO> subjectNoSuccess = subjectDtos, subjectSuccess = subjectDtos;

            foreach (var subject in subjectDtos)
            {
                if (subjects.FirstOrDefault(s => s.Id == subject.Id) == null)
                {
                    subjectNoSuccess = subjectNoSuccess.Where(element => element.Id != subject.Id);
                }
            }
            foreach (var subject in subjectDtos)
            {
                if (subjectNoSuccess.FirstOrDefault(s => s.Id == subject.Id) != null)
                {
                    subjectSuccess = subjectSuccess.Where(s => s.Id != subject.Id);
                }
            }

            if (searchProgress == "Успішні")
            {
                return(subjectSuccess);
            }
            else if (searchProgress == "Неуспішні")
            {
                return(subjectNoSuccess);
            }
            return(subjectDtos);
        }
        public async Task <IHttpActionResult> Get()
        {
            var result = await _educationService.Get();

            return(Ok(result));
        }
Ejemplo n.º 5
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 <EducationDTO> 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));
        }