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

package admin;

import entities.Users;
import helper.UserRole;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import manager.UserSessionBeanRemote;

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

    @EJB
    private UserSessionBeanRemote userSessionBean;
    Users user;
    String role;
    public CreateUser() {
        user = new Users();
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public String saveAction(){
            this.userSessionBean.newUser(user);
        return "login.jsp";
    }


    public String cancelAction(){
        return "login.jsp";
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
        if (role.equals("STUDENT"))
            user.setUserRole(UserRole.STUDENT);
        if (role.equals("TEACHER"))
            user.setUserRole(UserRole.TEACHER);
        if (role.equals("ADMIN"))
            user.setUserRole(UserRole.ADMIN);
    }


}
