public ActionResult Index()
 {
     RespMesas mesas = new RespMesas();
     try
     {
         SqlDataReader reader = null;
         SqlConnection myConnection = new SqlConnection();
         List<Mesa> listaMesas = new List<Mesa>();
         try {
             myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
             myConnection.Open();
             SqlCommand command = new SqlCommand("SELECT * FROM MESA WHERE MESA_STAT = 'ALTA';", myConnection);
             reader = command.ExecuteReader();
             while(reader.Read()){
                 Mesa mesa = new Mesa();
                 mesa.mesa_cve = reader["mesa_cve"].ToString();
                 mesa.mesa_des = reader["mesa_des"].ToString();
                 mesa.mesa_id = Convert.ToInt32(reader["mesa_id"].ToString());
                 mesa.mesa_stat = reader["mesa_stat"].ToString();
                 mesa.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                 mesa.ubic_consec = Convert.ToInt32(reader["ubic_consec"].ToString());
                 listaMesas.Add(mesa);
             }
             mesas.mesas = listaMesas;
         }catch(SqlException exc){
             mesas.success = false;
             mesas.message = "ERROR " + exc.Message;
         }
     }catch(Exception ex){
         mesas.success = false;
         mesas.message = "ERROR " + ex.Message;
     }
     mesas.success = true;
     mesas.message = "OK";
     return Json(mesas);
 }
        public ActionResult getMesas(ReqDeleteRestaurant rest)
        {
            log.Info("Solicitando getMesas");
            RespMesas mesas = new RespMesas();
            try
            {
                SqlDataReader reader = null;
                SqlConnection myConnection = new SqlConnection();
                List<Mesa> listaMesas = new List<Mesa>();
                try
                {
                    myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                    myConnection.Open();
                    SqlCommand command = new SqlCommand("SELECT * FROM MESA WHERE MESA_STAT = 'ALTA' AND REST_ID =@REST", myConnection);
                    command.Parameters.AddWithValue("@REST", rest.rest_id);
                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Mesa mesa = new Mesa();
                        mesa.mesa_cve = reader["mesa_cve"].ToString();
                        mesa.mesa_des = reader["mesa_des"].ToString();
                        mesa.mesa_id = Convert.ToInt32(reader["mesa_id"].ToString());
                        mesa.mesa_stat = reader["mesa_stat"].ToString();
                        mesa.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                        mesa.ubic_consec = Convert.ToInt32(reader["ubic_consec"].ToString());
                        listaMesas.Add(mesa);
                    }
                    mesas.mesas = listaMesas;
                    if (listaMesas.Count>0 )
                    {
                        mesas.success = true;
                        mesas.message = "OK";
                    }
                    else
                    {

                        mesas.success = false;
                        mesas.message = "No hay mesas disponibles";
                    }

                }
                catch (SqlException exc)
                {
                    log.Error("Error  SQLExc solicitando getMesas en " + exc.Message);
                    mesas.success = false;
                    mesas.message = "ERROR " + exc.Message;
                }
            }
            catch (Exception ex)
            {
                log.Error("Error solicitando getMesas en " + ex.Message);
                mesas.success = false;
                mesas.message = "ERROR " + ex.Message;
            }
            return Json(mesas);
        }
        public ActionResult getMesas(ReqMesa reqMesa)
        {
            RespMesas mesas = new RespMesas();
            SqlDataReader reader = null;
            SqlConnection myConnection = new SqlConnection();
            try
            {
                myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                myConnection.Open();
                SqlCommand command = new SqlCommand("SELECT * FROM MESA WHERE REST_ID =@REST AND UBIC_CONSEC = @CONSEC", myConnection);
                command.Parameters.AddWithValue("@REST", reqMesa.rest_id);
                command.Parameters.AddWithValue("@CONSEC", reqMesa.ubic_consec);
                reader = command.ExecuteReader();
                List<Mesa> listaMesas = new List<Mesa>();
                while (reader.Read())
                {
                    Mesa mesa = new Mesa();
                    mesa.mesa_cve = reader["mesa_cve"].ToString();
                    mesa.mesa_des = reader["mesa_des"].ToString();
                    mesa.mesa_id = Convert.ToInt32(reader["mesa_id"].ToString());
                    mesa.mesa_stat = reader["mesa_stat"].ToString();
                    mesa.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                    mesa.ubic_consec = Convert.ToInt32(reader["ubic_consec"].ToString());
                    listaMesas.Add(mesa);
                }
                mesas.mesas = listaMesas;
                mesas.success = true;
                mesas.message = "OK ";

            }
            catch (Exception ex)
            {
                mesas.success = false;
                mesas.message = "ERROR " + ex.Message;
                return Json(mesas);
            }
            finally
            {
                myConnection.Close();
            }
            return Json(mesas);
        }