/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package teacher;

import entities.Thesis;
import entities.Users;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import manager.SemesterSessionBeanRemote;
import manager.ThesisSessionBeanRemote;
import manager.UserSessionBeanRemote;

/**
 *
 * @author Szilárd
 */
@ManagedBean(name="CreateThesisT")
@RequestScoped
public class CreateThesisT {

    @EJB
    private SemesterSessionBeanRemote semesterSessionBean;
    @EJB
    private ThesisSessionBeanRemote thesisSessionBean;
    @EJB
    private UserSessionBeanRemote userSessionBean;


    Thesis thesis;
    Users user;
    /** Creates a new instance of CreateThesisT */
    public CreateThesisT() {
        Map map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        user = (Users) map.get("felhasznalo");
        thesis = new Thesis();
    }

    public Thesis getThesis() {
        return thesis;
    }

    public void setThesis(Thesis thesis) {
        this.thesis = thesis;
    }


    public String backAction(){
        return "listthesist";
    }

    public String saveAction(){
        thesis.setTeacherId(this.userSessionBean.findById(user.getId()));
        thesis.setSemesterId(this.semesterSessionBean.findOpen());
        this.thesisSessionBean.newThesis(thesis);
        return "listthesist.jsp";
    }

}
