package commands;

import java.io.IOException;

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

import spring.Context;

import dao.*;

public class TurmaRemover extends AbstractCommand {

	private TurmaDAO turmaDAO = DAOFactory.getInstance().getTurmaDAO();

	/*
	 * (não-Javadoc)
	 * 
	 * @see comandos.AbstractCommand#processarComando(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	public void processarComando(HttpServletRequest request,
			HttpServletResponse response, Context context) {
		// TODO Stub de método gerado automaticamente
		String idParam = request.getParameter("id");
		long id = Long.parseLong(idParam);

		String msg = turmaDAO.removerTurma(id);
		
		request.setAttribute("mensagem", msg);
		
		RequestDispatcher rd = request.getRequestDispatcher("Command?comando=TurmaPrepararRemocao");
		
		try {
			rd.forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
