public IEnumerable <ISpeaker> GetFilteredSpeakers(IEventFilters filters)
        {
            List <ISpeaker> result = null;

            // Remove any speaker filters first
            filters.SpeakerIds = new List <int>();
            var filteredSessionIds = _sessionRepository.FilterSessions(filters);

            if (filteredSessionIds != null)
            {
                var filteredSessions = _sessionRepository.GetSessionsInSessionIdList(filteredSessionIds);
                if (filteredSessions != null)
                {
                    var videoIds = _videoRepository.GetVideoIdListBySessionList(filteredSessions);
                    if (videoIds != null && videoIds.Count() > 0)
                    {
                        var speakerIds = _speakerVideoRepository.GetSpeakerIdListWhereInVideoIdList(videoIds);
                        if (speakerIds != null && speakerIds.Count() > 0)
                        {
                            result = _speakerRepository.GetWhereInSpeakerIdList(speakerIds).OrderBy(x => x.Name).ToList();
                        }
                    }
                }
            }
            return(result);
        }
        public IEnumerable <int> FilterSessions(IEventFilters filters)
        {
            IEnumerable <int> result = null;

            using (var conn = new SQLiteConnection(Database.DatabasePath))
            {
                using (var context = new DatabaseContext(conn))
                {
                    var query = context.Session.SelectMany(
                        session => context.SessionCategory.Where(sessionCategory => session.Id == sessionCategory.SessionId).DefaultIfEmpty(),
                        (session, sessionCategory) => new PresentationMetaData
                    {
                        SessionId  = session.Id,
                        CategoryId = sessionCategory.CategoryId,
                        //SpeakerIds = session.Speakerids,
                        EventName   = session.EventName,
                        EventYear   = session.EventYear,
                        Level       = session.Level,
                        SessionType = session.SessionType
                    });
                    if (filters.EventNames != null && filters.EventNames.Count > 0)
                    {
                        query = query.Where <PresentationMetaData>(p => filters.EventNames.Contains(p.EventName));
                    }
                    if (filters.EventYears != null && filters.EventYears.Count > 0)
                    {
                        query = query.Where <PresentationMetaData>(p => filters.EventYears.Contains(p.EventYear));
                    }
                    if (filters.Levels != null && filters.Levels.Count > 0)
                    {
                        query = query.Where <PresentationMetaData>(p => filters.Levels.Contains(p.Level));
                    }
                    if (filters.SessionTypes != null && filters.SessionTypes.Count > 0)
                    {
                        query = query.Where <PresentationMetaData>(p => filters.SessionTypes.Contains(p.SessionType));
                    }
                    if (filters.CategoryIds != null && filters.CategoryIds.Count > 0)
                    {
                        query = query.Where <PresentationMetaData>(p => filters.CategoryIds.Contains(p.CategoryId));
                    }
                    //if (filters.SpeakerIds != null && filters.SpeakerIds.Count > 0)
                    //{
                    //    query = query.Where<PresentationMetaData>(p => filters.SpeakerIds.Contains(p.SpeakerId));
                    //}
                    result = query.Select(p => p.SessionId).Distinct().ToList();
                }
            }
            return(result);
        }
        public IEnumerable <IPresentation> GetFilteredPresentations(IEventFilters filters)
        {
            // Check if filtered event and event years are already stored and if not download all event data
            _feedService.DownloadFilteredEventData(filters);

            // Get a list of Presentation objects
            List <IPresentation> presentations = null;

            // Get filtered Session ids
            var filteredSessionIds = _sessionRepository.FilterSessions(filters);

            if (filteredSessionIds != null)
            {
                var sessions = _sessionRepository.GetSessionsInSessionIdList(filteredSessionIds);

                // Filter for selected speakers
                if (filters.SpeakerIds != null && filters.SpeakerIds.Count() > 0)
                {
                    var videoIds      = _speakerVideoRepository.GetVideoIdListWhereInSpeakerIdList(filters.SpeakerIds);
                    var videos        = _videoRepository.GetVideosByVideoIdList(videoIds);
                    var videoMetaData = videos.Select(x => new { x.EventName, x.EventYear, x.SessionCode }).Distinct().ToList();

                    var filteredSessions = new List <ISession>();
                    foreach (var videoData in videoMetaData)
                    {
                        var sessionToAdd = sessions.Where(x => x.EventName == videoData.EventName && x.EventYear == videoData.EventYear && x.Code == videoData.SessionCode).FirstOrDefault();
                        if (sessionToAdd != null)
                        {
                            filteredSessions.Add(sessionToAdd);
                        }
                    }
                    sessions = filteredSessions;
                }

                if (sessions != null)
                {
                    var converter = new Converter <ISession, IPresentation>(SessionToPresentation);
                    presentations = sessions.ToList().ConvertAll(converter);
                    foreach (var presentation in presentations)
                    {
                        GetExtendedPresentationData(presentation);
                    }
                }
            }
            return(presentations);
        }
        public IEnumerable <string> GetFilteredSessionTypes(IEventFilters filters)
        {
            List <string> result = null;

            // Remove any session type filters first
            filters.SessionTypes = new List <string>();
            var filteredSessionIds = _sessionRepository.FilterSessions(filters);

            if (filteredSessionIds != null)
            {
                var filteredSessions = _sessionRepository.GetSessionsInSessionIdList(filteredSessionIds);
                if (filteredSessions != null)
                {
                    result = filteredSessions.Select(x => x.SessionType).Distinct().OrderBy(x => x).ToList();
                }
            }
            return(result);
        }
        public IEnumerable <ICategory> GetFilteredCategories(IEventFilters filters)
        {
            IEnumerable <ICategory> result = null;

            // Remove any category filters first
            filters.CategoryIds = new List <int>();
            var filteredSessionIds = _sessionRepository.FilterSessions(filters);

            if (filteredSessionIds != null)
            {
                var sessionCategories = _sessionCategoryRepository.FindBySessionId(filteredSessionIds);
                if (sessionCategories != null)
                {
                    var categoryIdList = sessionCategories.Select(x => x.CategoryId).Distinct().ToList();
                    result = _categoryRepository.GetCategoriesInSessionCategoryIdList(categoryIdList);
                }
            }
            return(result.OrderBy(x => x.Name).ToList());
        }
示例#6
0
        public void DownloadFilteredEventData(IEventFilters filters)
        {
            var events = GetEvents();

            if (filters.EventNames.Count() > 0)
            {
                foreach (var eventName in filters.EventNames)
                {
                    var eventMetaData = events.FirstOrDefault(x => x.Name == eventName);
                    if (filters.EventYears.Count() > 0)
                    {
                        foreach (var eventYear in eventMetaData.Years)
                        {
                            var yearFilter = filters.EventYears.FirstOrDefault(x => x == eventYear);
                            if (!string.IsNullOrEmpty(yearFilter))
                            {
                                // Check database for existing session data
                                var eventSessionDataCount = _sessionRepository.CountByEventNameAndYear(eventName, yearFilter);
                                if (eventSessionDataCount == 0)
                                {
                                    // Download session data for the event name and year
                                    eventSessionDataCount = DownloadAndSaveSessionData(eventName, yearFilter);
                                    if (eventSessionDataCount > 0)
                                    {
                                        foreach (var feed in VideoFeed.VideoFeeds)
                                        {
                                            feed.FeedYear = yearFilter;
                                            DownloadAndSaveVideoData(feed, eventName);
                                        }
                                        DownloadAndSaveSpeakerData(eventName, yearFilter);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }