public async Task <IActionResult> GetReccomendations( [FromRoute] int id) { var topics = _articleService.GetArticleTopics(id); var reccomendations = _articleService.GetReccomendedArticlesAsync( (await topics).Select(t => t.Id).ToList(), id); var model = (await reccomendations) .Select(r => ReccomendationBlockViewComponent.ToViewModel(r)) .ToList(); return(PartialView("ReccomendationsPartial", model)); }
public async Task <IActionResult> Get(string slug) { var article = await _context.Entries .Include(a => a.ApplicationUser) .Include(a => a.EntryToTopics) .ThenInclude(et => et.Topic) .FirstOrDefaultAsync(a => a.Slug == slug); // find Entries with similar topics // get topics linked to article var topics = article.EntryToTopics.Select(et => et.Topic); // get topic ids var topicIds = topics.Select(t => t.Id).ToList(); var reccomendations = await _context.Entries .Include(a => a.EntryToTopics) .Where(a => a.EntryToTopics.Any(et => topicIds.Contains(et.Topic.Id))) .Where(a => a.Id != article.Id) .OrderByDescending(a => a.Date) .AsNoTracking() .ToListAsync(); DisplayArticle model = new DisplayArticle() { Article = article, Topics = topics, Reccomendations = reccomendations.Select(r => ReccomendationBlockViewComponent.ToViewModel(r)) }; ViewData["OGTitle"] = article.HeadLine; ViewData["OGDescription"] = article.Paragraph; ViewData["OGImage"] = "https://www.renegadenews.net/images/uploads/" + article.Img; ViewData["OGUrl"] = "https://www.renegadenews.net/Article/" + article.Slug; // update page view article.PageViews++; _context.Entry(article).Property(p => p.PageViews).IsModified = true; await _context.SaveChangesAsync(); return(View("Index", model)); }