public ActionResult Index(Acceso login)
        {
            RespAcceso respuesta = new RespAcceso();
            try {
                SqlDataReader reader = null;
                SqlConnection myConnection = new SqlConnection();
                try
                {
                    myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                    myConnection.Open();
                    SqlCommand command = new SqlCommand("select * from RESTAURANT a, EMPLEADO b where b.EMPL_COD = " + login.num_empleado + " and a.REST_ID = " + login.rest_id + " and b.EMPL_STAT ='ALTA'", myConnection);
                    reader = command.ExecuteReader();
                    Empleado emp = new Empleado();
                    Restaurant rest = new Restaurant();
                    while (reader.Read())
                    {

                        rest.rest_des = reader["rest_des"].ToString();
                        rest.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                        rest.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
                        emp.empl_apm = reader["empl_apm"].ToString();
                        emp.empl_app = reader["empl_app"].ToString();
                        emp.empl_cod = Convert.ToInt32(reader["empl_cod"].ToString());
                        emp.empl_nom = reader["empl_nom"].ToString();
                        emp.empl_stat = reader["empl_stat"].ToString();
                        emp.empl_tipo = reader["empl_tipo"].ToString();
                        emp.succ_id = Convert.ToInt32(reader["succ_id"].ToString());

                    }//end while
                    respuesta.restaurant = rest;
                    respuesta.empleado = emp;
                }
                catch (SqlException sqlExc)
                {
                    respuesta.success = false;
                    respuesta.message = "ERROR " + sqlExc.Message;
                }
                finally
                {
                    myConnection.Close();
                }
                //fin try-catch SQL
            }catch(Exception ex){
                respuesta.success = false;
                respuesta.message = "ERROR " + ex.Message;
            }//Fin Try-catch General
            respuesta.success = true;
            respuesta.message = "OK";
            return Json(respuesta);
        }
 //
 // GET: /Restaurantes/
 public ActionResult Index(ReqEmpleado req)
 {
     RespRestaurant respuestaRestaurantes = new RespRestaurant();
     try {
         SqlDataReader reader = null;
         SqlConnection myConnection = new SqlConnection();
         try
         {
             myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
             myConnection.Open();
             SqlCommand command = new SqlCommand("select a.* from RESTAURANT a, EMPLEADO b where b.EMPL_COD = " + req.empl_cod + " and b.SUCC_ID = a.SUCC_ID and b.EMPL_STAT ='ALTA';  ", myConnection);
             reader = command.ExecuteReader();
             List<Restaurant> listaRestaurantes = new List<Restaurant>();
             while(reader.Read()){
                 Restaurant restaurante = new Restaurant();
                 restaurante.rest_des = reader["rest_des"].ToString();
                 restaurante.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                 restaurante.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
                 listaRestaurantes.Add(restaurante);
             }//fin while
             if(listaRestaurantes.Count==0){
                 respuestaRestaurantes.success = false;
                 respuestaRestaurantes.message += "NO EXISTEN EMPLEADOS ASOCIADOS AL NUMERO DE EMPLEADO";
                 return Json(respuestaRestaurantes);
             }
             respuestaRestaurantes.restaurantes = listaRestaurantes;
         }
         catch (SqlException exc)
         {
             respuestaRestaurantes.success = false;
             respuestaRestaurantes.message += "ERROR " + exc.Message;
             return Json(respuestaRestaurantes);
         }
         finally
         {
             myConnection.Close();//cerrando conexion de sql
         }//fin try-catch sql
     }catch(Exception ex){
         respuestaRestaurantes.success = false;
         respuestaRestaurantes.message += "ERROR " + ex.Message;
         return Json(respuestaRestaurantes);
     }//fin try-catch general
     respuestaRestaurantes.success = true;
     respuestaRestaurantes.message += "OK";
     return Json(respuestaRestaurantes);
 }
 public ActionResult getRestaurantes(ReqEmpleado req)
 {
     log.Info("Solicitando getRestaurantes");
     RespRestaurant respuestaRestaurantes = new RespRestaurant();
     try
     {
         SqlDataReader reader = null;
         SqlConnection myConnection = new SqlConnection();
         try
         {
             myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
             myConnection.Open();
             SqlCommand command = new SqlCommand("select a.* from restaurant a where a.succ_id = (select usr_succ_id from ff_cat_usuario where usr_numempleado="+ req.empl_cod+ " )  ", myConnection);
             reader = command.ExecuteReader();
             List<Restaurant> listaRestaurantes = new List<Restaurant>();
             while (reader.Read())
             {
                 Restaurant restaurante = new Restaurant();
                 restaurante.rest_des = reader["rest_des"].ToString();
                 restaurante.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                 restaurante.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
                 listaRestaurantes.Add(restaurante);
             }//fin while
             if (listaRestaurantes.Count == 0)
             {
                 respuestaRestaurantes.success = false;
                 respuestaRestaurantes.message = "Mesero Inexistente";
                 return Json(respuestaRestaurantes);
             }
             respuestaRestaurantes.restaurantes = listaRestaurantes;
         }
         catch (SqlException exc)
         {
             log.Error("Error en getRestaurantes SQLException en " + exc.Message);
             respuestaRestaurantes.success = false;
             respuestaRestaurantes.message += "ERROR " + exc.Message;
             return Json(respuestaRestaurantes);
         }
         finally
         {
             myConnection.Close();//cerrando conexion de sql
         }//fin try-catch sql
     }
     catch (Exception ex)
     {
         log.Error("Error en getRestaurantes Exception en " + ex.Message);
         respuestaRestaurantes.success = false;
         respuestaRestaurantes.message += "ERROR " + ex.Message;
         return Json(respuestaRestaurantes);
     }//fin try-catch general
     respuestaRestaurantes.success = true;
     respuestaRestaurantes.message += "OK";
     return Json(respuestaRestaurantes);
 }
        public ActionResult updateRestaurante(Restaurant rest)
        {
            Respuesta resp = new Respuesta();
            SqlConnection myConnection = new SqlConnection();
            try
            {
                myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                myConnection.Open();
                SqlCommand command = new SqlCommand("UPDATE RESTAURANT SET REST_DES = @DES  WHERE REST_ID = @ID AND SUCC_ID = @SUCC", myConnection);
                command.Parameters.AddWithValue("@ID", rest.rest_id);
                command.Parameters.AddWithValue("@DES", rest.rest_des);
                command.Parameters.AddWithValue("@SUCC", rest.succ_id);

                if (0 < command.ExecuteNonQuery())
                {
                    resp.success = true;
                    resp.message = "OK";
                }
                else
                {
                    resp.success = false;
                    resp.message = "NO HUBO ACTUALIZACION";
                }
                command.Parameters.Clear();
            }
            catch (SqlException ex)
            {
                resp.success = false;
                resp.message = "ERROR " + ex.Message;
                return Json(resp);
            }
            finally
            {
                myConnection.Close();
            }
            return Json(resp);
        }
 public ActionResult getRestaurantes(ReqGetRestaurant req)
 {
     RespRestaurant respuestaRestaurantes = new RespRestaurant();
     SqlDataReader reader = null;
     SqlConnection myConnection = new SqlConnection();
     try
     {
         myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
         myConnection.Open();
         SqlCommand command = new SqlCommand("SELECT * FROM RESTAURANT WHERE SUCC_ID = " + req.succ_id , myConnection);
         reader = command.ExecuteReader();
         List<Restaurant> listaRestaurantes = new List<Restaurant>();
         while (reader.Read())
         {
             Restaurant restaurante = new Restaurant();
             restaurante.rest_des = reader["rest_des"].ToString();
             restaurante.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
             restaurante.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
             listaRestaurantes.Add(restaurante);
         }
         respuestaRestaurantes.restaurantes = listaRestaurantes;
     }
     catch (SqlException ex)
     {
         respuestaRestaurantes.success = false;
         respuestaRestaurantes.message = "ERROR " + ex.Message;
         return Json(respuestaRestaurantes);
     }
     finally
     {
         myConnection.Close();
     }
     respuestaRestaurantes.success = true;
     respuestaRestaurantes.message = "OK";
     return Json(respuestaRestaurantes);
 }