package commands;

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

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

import spring.Context;

import business.Sala;
import dao.SalaDAO;

public class SalaAlterar extends AbstractCommand {

	SalaDAO salaDao = new SalaDAO();

	public void processarComando(HttpServletRequest request,
			HttpServletResponse response, Context context) {
		String id = request.getParameter("id");
		String numero = request.getParameter("numero");
		String bloco = request.getParameter("bloco");
		String campus = request.getParameter("campus");

		// String titulacao = request.getParameter("titulacao");

		Sala s1 = new Sala();
		s1.setNumero(numero);
		s1.setBloco(bloco);
		s1.setCampus(campus);
		s1.setId(Integer.parseInt(id));

		String msg = salaDao.atualizaSala(s1);

		List<Sala> salas = new ArrayList<Sala>();
		salas.add(s1);
		request.setAttribute("salas", salas);
		RequestDispatcher rd;
		if (msg != null)
			rd = request
					.getRequestDispatcher("salaAlterar.jsp?mensagem=" + msg);
		else
			rd = request
					.getRequestDispatcher("salaAlterar.jsp?mensagem=Sala Alterada com Sucesso!");
		try {
			rd.forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
