diff options
-rw-r--r-- | Main/Program.cs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Main/Program.cs b/Main/Program.cs index 0159873..808de98 100644 --- a/Main/Program.cs +++ b/Main/Program.cs @@ -20,14 +20,29 @@ namespace Main { PublishDate = 4
}
};
- string[] xmls = new [] {
+ string[] xmls = new[] {
await Download.DownloadXML("http://feeds.bbci.co.uk/news/rss.xml")
};
List<Article> articles = ParserService.ParseMultiple(xmls, configs).ToList();
Console.WriteLine(articles.Count);
using (var db = new DatabaseContext()) {
- articles.ForEach(async article => await db.Articles.AddAsync(article));
+ int start;
+ try {
+ start = db.Articles.Last().ArticleID;
+ } catch (Exception) {
+ start = 0;
+ }
+ var insertReady = articles.Select((article, index) => new Article() {
+ ArticleID = index + start,
+ Source = article.Source,
+ Title = article.Title,
+ Description = article.Description,
+ ArticleLink = article.ArticleLink,
+ ImageLink = article.ImageLink,
+ PublishDate = article.PublishDate
+ }).ToList();
+ insertReady.ForEach(async article => await db.Articles.AddAsync(article));
int records = await db.SaveChangesAsync();
Console.WriteLine($"Wrote {records} records!");
}
|