Esempio n. 1
0
 /// <summary>
 /// Metodo que modifica un itinerario de la base de datos
 /// </summary>
 /// <param name="it">el itinerario a modificar</param>
 /// <returns>true si modifica existosamente, false en caso de error</returns>
 public Itinerario ModificarItinerario(Itinerario it)
 {
     try
     {
         con = new ConexionBase();
         con.Conectar();
         comm             = new NpgsqlCommand("mod_itinerario", con.SqlConexion);
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, it.Id);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, it.Nombre);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Date, it.FechaInicio);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Date, it.FechaFin);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, it.IdUsuario);
         pgread = comm.ExecuteReader();
         pgread.Read();
         con.Desconectar();
         return(it);
     }
     catch (NpgsqlException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (InvalidCastException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (Exception e)
     {
         con.Desconectar();
         throw e;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Consulta si se desea recibir notificaciones por correo.
        /// </summary>
        /// <param name="id_usuario">Id del usuario al que se desea verificar si desea notificaciones por correo..</param>
        /// <returns>Retorna True en caso que se desee notificaciones y False en caso contrario</returns>
        public bool ConsultarNotificacion(int id_usuario)
        {
            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("consultar_notificaciones", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, id_usuario);
                pgread = comm.ExecuteReader();

                if (pgread.Read())
                {
                    return(pgread.GetBoolean(0));
                }
                con.Desconectar();
                return(false);
            }
            catch (NpgsqlException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (System.InvalidOperationException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Metodo para consultar el id del usuario a través de su nombre de usuario
        /// </summary>
        /// <param name="nombreUsuario">Nombre de usuario</param>
        /// <exception cref="NpgsqlException">Ocurrio un error al buscar en la base de datos</exception>
        /// <exception cref="Exception">Se desconoce la excepcion</exception>
        /// <returns>Id del usuario, si retorna -1 es que no existe</returns>
        public int ConsultarIdDelUsuario(string nombreUsuario)
        {
            int id;

            id = 0;
            try
            {
                conexion.Conectar();
                ConexionBase  con  = new ConexionBase();
                NpgsqlCommand comm = new NpgsqlCommand("consultarusuariosolonombre", conexion.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, nombreUsuario);
                NpgsqlDataReader pgread = comm.ExecuteReader();

                while (pgread.Read())
                {
                    id = pgread.GetInt32(0);
                }

                return(id);
            }
            catch (NpgsqlException e)
            {
                throw new BaseDeDatosExcepcion(e);
            }
            catch (Exception e)
            {
                return(-1);
            }
            finally
            {
                conexion.Desconectar();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Clase provisional para buscar usuario.
        /// </summary>
        /// <param name="id_usuario">id del usuario</param>
        /// <returns>El usuario cuyo id sea igual al parametro</returns>
        public Usuario Buscar_Usuario(int id_usuario)
        {
            Usuario Usuario = new Usuario();

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("consultarusuariosoloid", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, id_usuario);
                NpgsqlDataReader pgread = comm.ExecuteReader();

                //Se recorre los registros devueltos.
                if (pgread.Read())
                {
                    Usuario.NombreUsuario = pgread.GetString(0);
                    Usuario.Correo        = pgread.GetString(1);
                }
                con.Desconectar();
                return(Usuario);
            }
            catch (NpgsqlException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Metodo que modifica si el registro de notificaciones por correo  de la base de datos
 /// </summary>
 /// <param name="id_usuario">Id del usuario al que se desea modificar las notificaciones</param>
 /// <param name="correo">Variable que determina si se desea recibir o no, notificaciones por correo</param>
 /// <returns>True si modifica existosamente, false en caso de error</returns>
 public bool ModificarNotificacion(int id_usuario, bool correo)
 {
     try
     {
         con = new ConexionBase();
         con.Conectar();
         comm             = new NpgsqlCommand("modificar_notificacion", con.SqlConexion);
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, id_usuario);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Boolean, correo);
         //La siguiente linea determina si se desea recibir notificaciones push, en caso de implementarlo.
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Boolean, true);
         pgread = comm.ExecuteReader();
         con.Desconectar();
         return(true);
     }
     catch (NpgsqlException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (InvalidCastException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (Exception e)
     {
         con.Desconectar();
         throw e;
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Metodo que elimina el registro de la base de datos que determina si el usuario quiere notificaciones por correo
 /// </summary>
 /// <param name="id_usuario">Id del usuario al que se desea eliminar el registro</param>
 /// <returns>true si elimina existosamente, false en caso de error</returns>
 public Boolean EliminarNotificacion(int id_usuario)
 {
     try
     {
         con = new ConexionBase();
         con.Conectar();
         comm             = new NpgsqlCommand("eliminar_notificacion", con.SqlConexion);
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, id_usuario);
         pgread = comm.ExecuteReader();
         pgread.Read();
         Boolean resp = pgread.GetBoolean(0);
         con.Desconectar();
         return(resp);
     }
     catch (NpgsqlException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (Exception e)
     {
         con.Desconectar();
         throw e;
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Metodo que elimina un item existente de un itinerario existente
 /// </summary>
 /// <param name="it">item del cual se elimina el lugar turistico</param>
 /// <param name="lt">item a eliminar del itinerario</param>
 /// <returns>true si se elimino el item exitosamente, false en caso de error</returns>
 public Boolean EliminarItem_It(string tipo, int idit, int iditem)
 {
     try
     {
         con = new ConexionBase();
         con.Conectar();
         comm             = new NpgsqlCommand("del_item_it", con.SqlConexion);
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, tipo);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, iditem);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, idit);
         pgread = comm.ExecuteReader();
         pgread.Read();
         Boolean resp = pgread.GetBoolean(0);
         con.Desconectar();
         return(resp);
     }
     catch (NpgsqlException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (InvalidCastException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (Exception e)
     {
         con.Desconectar();
         throw e;
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Activar o desactivar la visibilidad del itinerario en el calendario
        /// </summary>
        /// <param name="idusuario">id del usuario al cual le pertenecen los itinerarios</param>
        /// <param name="iditinerario">id del itinerario a Activar/Desactivar</param>
        /// <param name="visible">parametro que determina si se activa(true) o desactiva(false) el itinerario en el calendario</param>
        /// <returns>true si se Activo/Desactivo exitosamente, false de lo contrario</returns>
        public Boolean SetVisible(int idusuario, int iditinerario, Boolean visible)
        {
            Boolean visible_sql = false;

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("setVisible", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, idusuario);
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Boolean, visible);
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, iditinerario);
                pgread = comm.ExecuteReader();
                pgread.Read();
                visible_sql = pgread.GetBoolean(0);
                con.Desconectar();
                return(visible_sql);
            }
            catch (NpgsqlException sql)
            {
                con.Desconectar();
                throw sql;
            }
            catch (InvalidCastException cast)
            {
                con.Desconectar();
                throw cast;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
        /**
         * <summary>Constructor que abre la base de datos</summary>
         * **/


        public PeticionLocalidadEvento()
        {
            try
            {
                conexion = new ConexionBase();
                conexion.Conectar();
            }
            catch (BaseDeDatosExcepcion e)
            {
                e.NombreMetodos.Add(this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name);
                throw e;
            }
        }
Esempio n. 10
0
        /**
         * <summary>Contructor de la clase</summary>
         * */


        public PeticionEvento()
        {
            try
            {
                conexion = new ConexionBase();
                conexion.Conectar();
            }
            catch (BaseDeDatosExcepcion e)
            {
                e.NombreMetodos.Add(this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name);
                e.Mensaje = "Problema al abrir conexion con base de datos en Peticiones de eventos";
                throw e;
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Metodo que agrega un lugar turistico existente a un itinerario existente
 /// </summary>
 /// <param name="it">itinerario al cual se le agrega el lugar turistico</param>
 /// <param name="lt">lugar turistico a agregar en el itinerario</param>
 /// <returns>true si se agrego el lugar turistico exitosamente, false en caso de error</returns>
 public Boolean AgregarItem_It(string tipo, int idit, int iditem, DateTime fechaini, DateTime fechafin)
 {
     try
     {
         con = new ConexionBase();
         con.Conectar();
         if ((tipo == "Lugar Turistico") || (tipo == "Actividad") || (tipo == "Evento"))
         {
             if (tipo == "Lugar Turistico")
             {
                 comm = new NpgsqlCommand("add_lugar_it", con.SqlConexion);
             }
             if (tipo == "Actividad")
             {
                 comm = new NpgsqlCommand("add_actividad_it", con.SqlConexion);
             }
             if (tipo == "Evento")
             {
                 comm = new NpgsqlCommand("add_evento_it", con.SqlConexion);
             }
         }
         else
         {
             con.Desconectar();
             return(false);
         }
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, iditem);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, idit);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Date, fechaini);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Date, fechafin);
         pgread = comm.ExecuteReader();
         pgread.Read();
         Boolean resp = pgread.GetBoolean(0);
         con.Desconectar();
         return(resp);
     }
     catch (NpgsqlException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (Exception e)
     {
         con.Desconectar();
         throw e;
     }
 }
Esempio n. 12
0
        /// <summary>
        ///  Consulta los lugares turisticos por nombre, o similiares.
        /// </summary>
        /// <param name="busqueda">Palabra cuya similitud se busca en el nombre de la actividad que se esta buscando.</param>
        /// <returns>Retorna una lista con las actividades que tengan coincidencia.</returns>
        public List <Actividad> ConsultarActividades(string busqueda)
        {
            List <Actividad> list_actividades = new List <Actividad>();

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("consultar_actividades", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, busqueda);
                pgread = comm.ExecuteReader();

                //Se recorre los registros devueltos.
                while (pgread.Read())
                {
                    Actividad actividad = new Actividad();
                    actividad.Id     = pgread.GetInt32(0);
                    actividad.Nombre = pgread.GetString(1);
                    //actividad.Foto = pgread.GetString(2);


                    list_actividades.Add(actividad);
                }

                con.Desconectar();
                return(list_actividades);
            }
            catch (NpgsqlException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
Esempio n. 13
0
 /// <summary>returns
 /// Metodo que agrega en la base de datos un nuevo itinerario
 /// </summary>
 /// <param name="it">el itinerario a agregar</param>
 /// <returns>true si agrega existosamente, false en caso de error</>
 public Itinerario AgregarItinerario(Itinerario it)
 {
     try
     {
         con = new ConexionBase();
         con.Conectar();
         comm             = new NpgsqlCommand("add_itinerario", con.SqlConexion);
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, it.Nombre);
         comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, it.IdUsuario);
         pgread = comm.ExecuteReader();
         pgread.Read();
         it.Id     = pgread.GetInt16(0);
         it.Nombre = pgread.GetString(1);
         con.Desconectar();
         return(it);
     }
     catch (NpgsqlException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (InvalidCastException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (NullReferenceException e)
     {
         con.Desconectar();
         throw e;
     }
     catch (Exception e)
     {
         con.Desconectar();
         throw e;
     }
 }
Esempio n. 14
0
        //----------------------------------------------------------------------------------------------
        /// <summary>
        /// Metodo que agrega en la base de datos si el usuario desea recibir notificaciones por correo
        /// </summary>
        /// <param name="id_usuario">Id del usuario a que se le agregara el registro</param>
        /// <returns>true si agrega existosamente, false en caso de error</>
        public bool AgregarNotificacion(int id_usuario)
        {
            bool rs;

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("agregar_notificacion", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, id_usuario);
                pgread = comm.ExecuteReader();
                pgread.Read();
                rs = pgread.GetBoolean(0);
                con.Desconectar();
                return(rs);
            }
            catch (NpgsqlException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (InvalidCastException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (NullReferenceException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Consulta los lugares turisticos por nombre, o similiares.
        /// </summary>
        /// <param name="busqueda">Palabra cuya similitud se busca en el nombre del lugar turistico que se esta buscando.</param>
        /// <returns>Retorna una lista con los lugares turisticos que tengan coincidencia.</returns>
        public List <LugarTuristico> ConsultarLugarTuristico(string busqueda)
        {
            List <LugarTuristico> list_lugaresturisticos = new List <LugarTuristico>();

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("consultar_lugarturistico", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, busqueda);
                pgread = comm.ExecuteReader();

                //Se recorre los registros devueltos.
                while (pgread.Read())
                {
                    LugarTuristico lugarTuristico = new LugarTuristico();
                    lugarTuristico.Id     = pgread.GetInt32(0);
                    lugarTuristico.Nombre = pgread.GetString(1);

                    list_lugaresturisticos.Add(lugarTuristico);
                }

                con.Desconectar();
                return(list_lugaresturisticos);
            }
            catch (NpgsqlException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Consulta los eventos por nombre, o similiares.
        /// </summary>
        /// <param name="busqueda">Palabra cuya similitud se busca en el nombre del evento que se esta buscando.</param>
        /// <returns>Retorna una lista con los eventos que tengan coincidencia.</returns>
        public List <Evento> ConsultarEventos(string busqueda, DateTime fechainicio, DateTime fechafin)
        {
            List <Evento> list_eventos = new List <Evento>();

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("consultar_eventos", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Varchar, busqueda);
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Date, fechainicio);
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Date, fechafin);
                pgread = comm.ExecuteReader();

                //Se recorre los registros devueltos.
                while (pgread.Read())
                {
                    Evento evento = new Evento(pgread.GetInt32(0), pgread.GetString(1));
                    evento.Foto = pgread.GetString(2);
                    list_eventos.Add(evento);
                }

                con.Desconectar();
                return(list_eventos);
            }
            catch (NpgsqlException e)
            {
                con.Desconectar();
                throw e;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }
Esempio n. 17
0
 public PeticionPerfil()
 {
     conexion = new ConexionBase();
 }
Esempio n. 18
0
 public PeticionLogin()
 {
     conexion = new ConexionBase();
 }
Esempio n. 19
0
 public PeticionItinerario()
 {
     con = new ConexionBase();
 }
Esempio n. 20
0
        public List <Itinerario> ConsultarItinerariosCorreo(int id_usuario)
        {
            List <Itinerario> itinerarios = new List <Itinerario>(); // Lista de itinerarios de un usuario

            try
            {
                con = new ConexionBase();
                con.Conectar();
                comm             = new NpgsqlCommand("consultar_itinerarios_correo", con.SqlConexion);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue(NpgsqlTypes.NpgsqlDbType.Integer, id_usuario);
                NpgsqlDataReader pgread = comm.ExecuteReader();
                int auxiliar            = 0;
                //Recorremos los registros devueltos
                while (pgread.Read())
                {
                    Itinerario iti;
                    if (!pgread.IsDBNull(2) && (!pgread.IsDBNull(3)))
                    {
                        iti = new Itinerario(pgread.GetInt32(0), pgread.GetString(1), pgread.GetDateTime(2), pgread.GetDateTime(3), id_usuario, true);
                    }
                    else
                    {
                        iti = new Itinerario(pgread.GetInt32(0), pgread.GetString(1), id_usuario, true);
                    }

                    //Se revisa si el registro de itinerario en la base ya se encuentra en la lista de itinerarios del usuario
                    if (itinerarios.Count == 0)
                    {
                        itinerarios.Add(iti);
                    }
                    foreach (Itinerario itinerario in itinerarios)
                    {
                        if (itinerario.Id == iti.Id)
                        {
                            auxiliar = 1;
                        }
                    }
                    if (auxiliar != 1)
                    {
                        itinerarios.Add(iti);
                    }
                    auxiliar = 0;

                    //Agregamos los eventos, actividades y lugares a la lista correspondiente
                    //Si existe lugar turistico en este registro
                    if (!pgread.IsDBNull(4))
                    {
                        dynamic lugar = new System.Dynamic.ExpandoObject();
                        lugar.Nombre      = pgread.GetString(4);
                        lugar.Descripcion = pgread.GetString(5);
                        lugar.Tipo        = "Lugar Turistico";

                        itinerarios[itinerarios.Count - 1].Items_agenda.Add(lugar);
                    }

                    //Si existe actividad en este registro
                    if (!pgread.IsDBNull(6))
                    {
                        dynamic actividad = new System.Dynamic.ExpandoObject();
                        actividad.Nombre      = pgread.GetString(6);
                        actividad.Descripcion = pgread.GetString(7);
                        actividad.Tipo        = "Actividad";

                        itinerarios[itinerarios.Count - 1].Items_agenda.Add(actividad);
                    }

                    //Si existe eventos en este registro.
                    if (!pgread.IsDBNull(8))
                    {
                        dynamic evento = new System.Dynamic.ExpandoObject();
                        evento.Nombre      = pgread.GetString(8);
                        evento.Descripcion = pgread.GetString(9);
                        evento.Tipo        = "Evento";

                        itinerarios[itinerarios.Count - 1].Items_agenda.Add(evento);
                    }
                }
                con.Desconectar();
                return(itinerarios);
            }
            catch (NpgsqlException sql)
            {
                con.Desconectar();
                throw sql;
            }
            catch (ArgumentException arg)
            {
                con.Desconectar();
                throw arg;
            }
            catch (InvalidCastException cast)
            {
                con.Desconectar();
                throw cast;
            }
            catch (Exception e)
            {
                con.Desconectar();
                throw e;
            }
        }