public static List <NotificacionQueryEntidad> mostrarNotificacionesSolicitudes(int idUsuario) { List <NotificacionQueryEntidad> listaNotificacion = new List <NotificacionQueryEntidad>(); NotificacionQueryEntidad notificacion = null; SqlConnection cn = new SqlConnection(); cn.ConnectionString = ConnectionString.Cadena(); cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = @" SELECT DISTINCT n.id, n.nombreEmisor as emisor, n.texto, n.idEncuentro, e.nombre as estado, n.nombreReceptor as receptor, n.idEmisor, n.idReceptor FROM Notificacion n, Estado e WHERE e.id = n.idEstado AND n.idEstado != 11 AND n.idEstado != 13 AND n.idEncuentro = 0"; if (idUsuario != 0) { cmd.CommandText += @" AND n.idReceptor = @id"; cmd.Parameters.AddWithValue("@id", idUsuario); } SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { notificacion = new NotificacionQueryEntidad(); notificacion.idNotificacion = int.Parse(dr["id"].ToString()); notificacion.nombreEmisor = dr["emisor"].ToString(); notificacion.texto = dr["texto"].ToString(); notificacion.idEncuentro = int.Parse(dr["idEncuentro"].ToString()); notificacion.nombreEstado = dr["estado"].ToString(); notificacion.idReceptor = int.Parse(dr["idReceptor"].ToString()); notificacion.idEmisor = int.Parse(dr["idEmisor"].ToString()); notificacion.nombreReceptor = dr["receptor"].ToString(); listaNotificacion.Add(notificacion); } dr.Close(); cn.Close(); return(listaNotificacion); }
// public static List<Notificacion> mostrarNotificaciones() { public static List <NotificacionQueryEntidad> mostrarNotificaciones(int idUsuario) { List <NotificacionQueryEntidad> listaNotificacion = new List <NotificacionQueryEntidad>(); NotificacionQueryEntidad notificacion = null; SqlConnection cn = new SqlConnection(); cn.ConnectionString = ConnectionString.Cadena(); cn.Open(); SqlCommand cmd = new SqlCommand("sp_NotificacionDao_mostrarNotificaciones", cn); cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@usuario", idUsuario); cmd.Parameters.AddWithValue("@idUsuario", idUsuario); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { notificacion = new NotificacionQueryEntidad(); notificacion.idNotificacion = int.Parse(dr["id"].ToString()); notificacion.nombreEmisor = dr["emisor"].ToString(); notificacion.nombreReceptor = dr["receptor"].ToString(); notificacion.texto = dr["texto"].ToString(); notificacion.idEncuentro = int.Parse(dr["idEncuentro"].ToString()); notificacion.nombreEstado = dr["estado"].ToString(); // DateTime fi; if (DateTime.TryParse(dr["fechaInicioEncuentro"].ToString(), out fi)) { notificacion.fecha = fi; } // DateTime hi; if (DateTime.TryParse(dr["horaInicio"].ToString(), out hi)) { notificacion.horainicio = hi; } // ok listaNotificacion.Add(notificacion); } dr.Close(); cn.Close(); return(listaNotificacion); }