@Override public Collection<StudentDTO> getStudents() { ArrayList<StudentDTO> studentDTOs = new ArrayList<>(); Query query = entityManager.createNamedQuery("Student.findAll"); List<Student> students = query.getResultList(); for (Student s : students) { studentDTOs.add(new StudentDTO(s.getFirstName(), s.getLastName(), s.getCpr())); } return studentDTOs; }
@Override public boolean assignStudentElectives(Collection<StudentElectiveDTO> studentElective) { for (StudentElectiveDTO studentElectiveDTO : studentElective) { Student student = entityManager.find(Student.class, studentElectiveDTO.getCPR()); Elective elective = entityManager.find(Elective.class, studentElectiveDTO.getElective_id()); student.addElective(elective); elective.addStudent(student); entityManager.persist(elective); entityManager.persist(student); } return true; }
@Override public boolean addFirstRndStudentChoice(FirstVoteDTO firstVote) { try { Elective e1, e2, e3, e4; e1 = findElectiveById(firstVote.getFirstPriority1().getElectiveID()); e2 = findElectiveById(firstVote.getFirstPriority2().getElectiveID()); e3 = findElectiveById(firstVote.getSecondPriority1().getElectiveID()); e4 = findElectiveById(firstVote.getSecondPriority2().getElectiveID()); Student st = findStudentById(firstVote.getStudent().getCpr()); FirstRoundVote frv = new FirstRoundVote(st.getCpr(), st, e1, e2, e3, e4); entityManager.persist(frv); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
public String execute() { StudentManager stdMng = new StudentManager(); Student student = new Student(); StudentClass stdClass = new StudentClass(); stdClass.setId(bean.getStudentClassID()); student.setCode(bean.getCode()); student.setFullName(bean.getFullName()); student.setPhoto(bean.getPhoto()); student.setPhone(bean.getPhone()); student.setPass(bean.getPass()); student.setBirthDate(bean.getBirthDate()); student.setEmail(bean.getEmail()); student.setGender(bean.getGender()); student.setAddress(bean.getAddress()); student.setActive(bean.isActive()); student.setStudentClass(stdClass); User user = (User) ActionContext.getContext().getSession().get("user"); student.setUser(user); stdMng.update(student); if (stdMng.updateStudent(student)) { addActionMessage("Update Student Successfully !!!"); return SUCCESS; } else { addActionError("Update Student Unsuccessfully !!!"); return ERROR; } }