package commands;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import business.Disciplina;
import dao.FacadeDAO;

public class DisciplinaCria extends AbstractCommand {

	public DisciplinaCria() {
		super();
	}

	@Override
	// public void executarComando(HttpServletRequest request,
	// HttpServletResponse response) throws IOException, ServletException {
	public void processarComando(HttpServletRequest request,
			HttpServletResponse response, HttpServlet servlet)
			throws IOException, ServletException {
		String codigo = request.getParameter("codigo");
		String nome = request.getParameter("nome");
		String cargaHoraria = request.getParameter("cargaHoraria");
		String criar = request.getParameter("criar");
		if (criar.equals("sim"))
			FacadeDAO.getInstance(servlet).getDisciplinaDAO().cria(codigo,
					nome, Integer.parseInt(cargaHoraria));
		ArrayList<Disciplina> disciplinas = (ArrayList<Disciplina>) FacadeDAO
				.getInstance(servlet).getDisciplinaDAO().listaDados();
		request.setAttribute("disciplinas", disciplinas);
		RequestDispatcher rd = request
				.getRequestDispatcher("disciplinaCria.jsp");
		rd.forward(request, response);
	}

}
