public async Task <IActionResult> Aggregate([Bind("Id,Title,Content,Url,Rating,NewsDate,DateCollect,RssSourceId")] NewsDto news) { try { var rssSources = (await _rssSourceService.GetRssSources()); Log.Information("***Try to aggregate news"); var allSourcesNews = new List <NewsDto>(); foreach (var rssSource in rssSources) { Log.Information($"Aggregate from {rssSource.Name}"); var oneSourceNewsList = await _newsService.GetNewsFromRssSource(rssSource); Log.Information($"News in rss source: {oneSourceNewsList.Count()}"); foreach (var oneSourceNews in oneSourceNewsList) { if (rssSource.Name == "Igromania") { oneSourceNews.Body = await _igromaniaParser.Parse(oneSourceNews.Url); } if (rssSource.Name == "Shazoo") { oneSourceNews.Body = await _shazooParser.Parse(oneSourceNews.Url); } if (rssSource.Name == "Onliner") { oneSourceNews.Body = await _onlinerParser.Parse(oneSourceNews.Url); } if (rssSource.Name == "4Pda") { oneSourceNews.Body = await _4PdaParser.Parse(oneSourceNews.Url); } if (rssSource.Name == "Wylsa") { oneSourceNews.Body = await _wylsaParser.Parse(oneSourceNews.Url); } } allSourcesNews.AddRange(oneSourceNewsList); Log.Information($"Finished aggregate from {rssSource.Name}"); } Log.Information($"***Total aggregated news count {allSourcesNews.Count()}"); await _newsService.AddRange(allSourcesNews); } catch (Exception e) { Log.Error(e, $"Failed to aggregate news "); throw; } return(RedirectToAction(nameof(Index), (new Guid("E3512D7D-381A-4655-8B60-584C08D9254A")))); }
// GET: RssSources public async Task <IActionResult> Index() { return(View(await _rssService.GetRssSources())); }
public async Task <IActionResult> Get(Guid id) { var news = await _rssSourceService.GetRssSources(id); return(Ok(news)); }