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 updateMesa(Mesa mesa)
        {
            Respuesta resp = new Respuesta();
            SqlConnection myConnection = new SqlConnection();
            try
            {
                myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                myConnection.Open();
                SqlCommand command = new SqlCommand("UPDATE MESA SET MESA_CVE = @MESACVE, MESA_DES =@MESADES, MESA_STAT =@MESASTAT, REST_ID = @RESTID, UBIC_CONSEC= @UBIC WHERE MESA_ID = @MESAID", myConnection);
                command.Parameters.AddWithValue("@MESACVE", mesa.mesa_cve);
                command.Parameters.AddWithValue("@MESADES", mesa.mesa_des);
                command.Parameters.AddWithValue("@RESTID", mesa.rest_id);
                command.Parameters.AddWithValue("@UBIC", mesa.ubic_consec);
                command.Parameters.AddWithValue("@MESAID", mesa.mesa_id);
                command.Parameters.AddWithValue("@MESASTAT", mesa.mesa_stat);

                if (0 < command.ExecuteNonQuery())
                {
                    resp.success = true;
                    resp.message = "OK";
                }
                else
                {
                    resp.success = false;
                    resp.message = "NO SE CREO LA UBICACION";
                    return Json(resp);
                }
            }
            catch (Exception ex)
            {
                resp.success = false;
                resp.message = "ERROR " + ex.Message;
                return Json(resp);
            }
            finally
            {
                myConnection.Close();
            }
            return Json(resp);
        }
        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);
        }