Пример #1
0
        public PartialViewResult GetFeed(string feedUrl, string searchParam)
        {
            var configSettings = RSSHelpers.GetConfigurationSettings();
            var rssFeedUrls    = from feed in configSettings.Descendants("feed")
                                 select new
            {
                Url = feed.Attribute("url").Value
            };


            var feeds = (from feed in rssFeedUrls
                         let feedDoc = XDocument.Load(feed.Url)
                                       where feed.Url.Contains(feedUrl)
                                       select new Feed
            {
                Url = feed.Url,
                Title = feedDoc.Root.Element("channel").Element("title").Value,
                Items = (from item in feedDoc.Descendants("item")
                         //orderby item.Element("pubDate").Value descending
                         where item.Element("title").ElementContainsIgnoreCase(searchParam) || item.Element("link").ElementContainsIgnoreCase(searchParam) ||
                         item.Element("pubDate").ElementContainsIgnoreCase(searchParam) || item.Element("description").ElementContainsIgnoreCase(searchParam)
                         select new Item
                {
                    Title = item.Element("title") == null ? "No Title" : item.Element("title").Value,
                    Link = item.Element("link") == null ? "No Link" : item.Element("link").Value,
                    PublicationDate = item.Element("pubDate") == null ? DateTime.MinValue : Convert.ToDateTime(item.Element("pubDate").Value),
                    Description = item.Element("description") == null ? "Description Unavailable" : item.Element("description").Value
                })
            })
                        .FirstOrDefault();

            return(PartialView("Partials/SingleItem", feeds));
        }
Пример #2
0
        public PartialViewResult GetFeeds(DateTime lastStory, string searchString)
        {
            var configSettings = RSSHelpers.GetConfigurationSettings();
            var rssFeedUrls    = from feed in configSettings.Descendants("feed")
                                 select new
            {
                Url = feed.Attribute("url").Value
            };


            var feeds = from feed in rssFeedUrls
                        let feedDoc = XDocument.Load(feed.Url)
                                      select new Feed
            {
                Url   = feed.Url,
                Title = feedDoc.Root.Element("channel").Element("title").Value,
                Items = (from item in feedDoc.Descendants("item")
                         //orderby item.Element("pubDate").Value descending
                         select new Item
                {
                    Title = item.Element("title") == null ? "No Title" : item.Element("title").Value,
                    Link = item.Element("link") == null ? "No Link" : item.Element("link").Value,
                    PublicationDate = item.Element("pubDate") == null ? DateTime.MinValue : Convert.ToDateTime(item.Element("pubDate").Value),
                    Description = item.Element("description") == null ? "Description Unavailable" : item.Element("description").Value
                })
            };

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                feeds = ApplySearchParameters(feeds, searchString);
            }

            return(PartialView("Partials/Item", feeds));
        }