public async Task <IActionResult> GetLatestNews() { var iNews = await _dbContext.News.Include(p => p.Photo).Where(inews => inews.IsImportant == true).OrderByDescending(x => x.AddedAt).ToListAsync(); var importantNewsFromAllSections = iNews.Take(7).ToList(); var importantNewsToReturn = NewsForHomeDto.Map(importantNewsFromAllSections).ToList(); var polandNews = await GetNewsForHomeComponent("poland", importantNewsFromAllSections); var policyNews = await GetNewsForHomeComponent("policy", importantNewsFromAllSections); var sportNews = await GetNewsForHomeComponent("sport", importantNewsFromAllSections); var businessNews = await GetNewsForHomeComponent("business", importantNewsFromAllSections); var worldNews = await GetNewsForHomeComponent("world", importantNewsFromAllSections); var lNews = await _dbContext.News.Include(p => p.Photo).OrderByDescending(x => x.AddedAt).ToListAsync(); var latestNews = LatestNewsDto.Map(lNews.Take(30).ToList()); var dataToReturn = new DataForHomeComponent() { ImportantNews = importantNewsToReturn, SectionPolandNews = polandNews, SectionBusinessNews = businessNews, SectionPolicyNews = policyNews, SectionSportNews = sportNews, SectionWorldNews = worldNews, LatestNews = latestNews }; return(Ok(dataToReturn)); }
public async Task <IActionResult> GetNews(long id) { News news = await _dbContext.News.Include(u => u.Author).Include(p => p.Photo) .FirstOrDefaultAsync(n => n.Id == id); if (news != null) { var newsToReturn = NewsForDetailsDto.Map(news); List <Comment> comments = await _dbContext.Comments.Include(a => a.Author) .Where(c => c.NewsId == id).ToListAsync(); var commentsToReturn = CommentDto.Map(comments); newsToReturn.Comments = commentsToReturn; List <News> x = await _dbContext.News.Include(p => p.Photo) .Where(s => s.Section == newsToReturn.Section && s.Id != id) .OrderByDescending(z => z.AddedAt).ToListAsync(); List <LatestNewsDto> otherInfotoReturn = LatestNewsDto.Map(x.Take(5).ToList()); return(Ok(new DataForNewsDetailsComponentDto { NewsForDetails = newsToReturn, NewsForOtherInfos = otherInfotoReturn })); } else { return(NoContent()); } }