예제 #1
0
		private void SaveFilteredRssNews(List<XElement> rssNews)
		{
			if (rssNews.Count == 0)
			{
				return;
			}

			using (var db = NewsDataContext.Create())
			{
				foreach (XElement rssItem in rssNews)
				{
					NewsItem news = new NewsItem();
					news.IsRead = false;

					XElement linkElement = rssItem.Element("link");
					if (linkElement == null)
					{
						// Wenn Artikel-URL fehlt, ist die News nichts wert
						continue;
					}

					news.Link = rssItem.Element("link").Value;

					XElement descriptionElement = rssItem.Element("description");
					string preview = descriptionElement != null ? descriptionElement.Value : "";
					news.Preview = preview;

					XElement publishDateElement = rssItem.Element("pubDate");
					if (publishDateElement != null)
					{
						news.PublishDate = DateTime.Parse(publishDateElement.Value);
					}

					XElement thumbnailElement = rssItem.Element("enclosure");
					if (thumbnailElement != null && thumbnailElement.Attribute("url") != null)
					{
						news.Thumbnail = thumbnailElement.Attribute("url").Value;
					}

					XElement titleElement = rssItem.Element("title");
					if (titleElement != null)
					{
						news.Title = titleElement.Value;
					}

					db.News.InsertOnSubmit(news);
				}

				db.SubmitChanges();
			}
		}
예제 #2
0
		public void MarkAsRead(NewsItem news)
		{
			using (var db = NewsDataContext.Create())
			{
				var loadedNews = db.News.Single(n => n.Id == news.Id);
				loadedNews.IsRead = true;
				db.SubmitChanges();
			}

			news.IsRead = true;
		}