public ActionResult Index() { var now = DateTime.Now.Date; var highlights = _articleHighlightAllRepository.GetMany(hl => DbFunctions.TruncateTime(hl.StartDate) <= now && DbFunctions.TruncateTime(hl.EndDate) >= now && hl.Article.ArticleStatus == (int)ArticleStatus.Good) .OrderBy(hl => hl.Order).Take(4).ToList(); if (highlights.Count < 4) { highlights = _articleHighlightAllRepository.All.Where(hl => hl.Article.ArticleStatus == (int)ArticleStatus.Good).OrderBy(hl => hl.Article.PublishedTime).Take(4).ToList(); } var articles = _articleRepository.All.Where(a => a.SeriesOrder <= 1 && a.IsPublished && a.ArticleStatus == (int)ArticleStatus.Good && DbFunctions.TruncateTime(a.PublishedTime) <= now) .OrderByDescending(a => a.PublishedTime) .ThenBy(a => a.Order).ToList(); articles = articles.Except(articles.Where(art => highlights.Any(hl => hl.Id == art.Id))).ToList(); ViewBag.Highlights = highlights.Select(hl => hl.Article).ToList(); ViewBag.artCategory = _articleCategoryRepository.GetMany(c => c.ParentId == null || c.ParentId == 0); return(View(articles)); }
public ActionResult Index() { var now = DateTime.Now.Date; var highlights = _articleHighlightAllRepository.GetMany(hl => DbFunctions.TruncateTime(hl.StartDate) <= now && DbFunctions.TruncateTime(hl.EndDate) >= now && hl.Article.ArticleStatus == (int)ArticleStatus.Good) .OrderBy(hl => hl.Order).Take(4).ToList(); if (highlights.Count < 4) { highlights = _articleHighlightAllRepository.All.Where(hl => hl.Article.ArticleStatus == (int)ArticleStatus.Good).OrderBy(hl => hl.Article.PublishedTime).Take(4).ToList(); } //Get All Article with conditions var list = _articleRepository.All.Where(a => a.SeriesOrder <= 1 && a.IsPublished && a.ArticleStatus == (int)ArticleStatus.Good && DbFunctions.TruncateTime(a.PublishedTime) <= now) .OrderByDescending(a => a.PublishedTime) .ThenBy(a => a.Order).ToList(); // Get Top video var vdCatGroups = _videoCategoryRepository.All.Where(vc => vc.PageGroupId == (int)PageType.Startup) .Select(g => new VideoCatGroupView { Id = g.Id, Name = g.Name, UniqueTitle = g.UniqueTitle }).ToList(); foreach (var cat in vdCatGroups) { cat.NewestVideos = _videoRepository.GetMany(v => v.Category.Id == cat.Id && v.IsPublished && v.PublishedTime <= DateTime.Now) .OrderByDescending(v => v.DisplayTime).Take(3).ToList(); } var homeModel = new HomeModel { HotArticles = list.Except(list.Where(art => highlights.Any(hl => hl.Id == art.Id))).ToList(), VideoCatGroups = vdCatGroups }; ViewBag.Highlights = highlights; ViewBag.artCategory = _articleCategoryRepository.GetMany(c => c.ParentId == null || c.ParentId == 0); return(View(homeModel)); }