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

package paqueteCMD;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import paqueteBL.*;
import paqueteDAO.HostDAO;
import paqueteView.HostView;

public class cmdHost implements interfaceCMD{

public String procesa(String accion,HttpServletRequest request, HttpServletResponse response) throws Exception
{
    if (accion.equals("crearVM")) return crearVM(request,response);
    else if (accion.equals("mantenimiento")) return mantenimiento(request,response);
    else if (accion.equals("normal")) return salirMantenimiento(request,response);
    else if (accion.equals("guardar")) return guardar(request,response);
    else
        return verHost(accion,request,response);
}


public String crearVM(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    return "/viewNewVM.jsp";
}

public String mantenimiento(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    int id;
    id=Integer.valueOf(request.getParameter("id"));
    Host host=new FvcBL().mantenimientoHOST(id);
    return HostView.verHost(request, host);
}

public String salirMantenimiento(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    int id;
    id=Integer.valueOf(request.getParameter("id"));
    Host host=new FvcBL().salirMantenimientoHOST(id);
    return HostView.verHost(request, host);
}

public String verHost(String accion,HttpServletRequest request, HttpServletResponse response) throws Exception
{
    int id;
    id=Integer.valueOf(request.getParameter("id"));
    Host host=new FvcBL().loadCompletoHost(id);
    return HostView.verHost(request, host);
}

public String guardar(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    int id;
    id=Integer.valueOf(request.getParameter("id"));
    String nombre=request.getParameter("txtNombre");
    String ip=request.getParameter("txtIP");
    String usuario=request.getParameter("txtUsuario");
    String password=request.getParameter("txtPassword");
    Host host=new Host();
    host.setId(id);
    host.setNombre(nombre);
    host.setIp(ip);
    host.setPassword(password);
    host.setUser(usuario);
    host=new FvcBL().updateHost(host);
    return HostView.verHost(request, host);
}

}