public async Task <ActionResult> Index([FromServices] IFastShareService fastShareService) { var banners = AdsService.GetsByWeightedPrice(8, AdvertiseType.Banner, Request.Location()).OrderByRandom().ToList(); var fastShares = await fastShareService.GetAllFromCacheAsync(s => s.Sort); var postsQuery = PostService.GetQuery(PostBaseWhere().And(p => p.Status == Status.Published)); //准备文章的查询 var posts = await postsQuery.Where(p => !p.IsFixedTop).OrderBy(OrderBy.ModifyDate.GetDisplay() + " desc").ToCachedPagedListAsync <Post, PostDto>(1, 15, MapperConfig); posts.Data.InsertRange(0, postsQuery.Where(p => p.IsFixedTop).OrderByDescending(p => p.ModifyDate).ProjectTo <PostDto>(MapperConfig).Cacheable().ToList()); var viewModel = await GetIndexPageViewModel(); viewModel.Banner = banners; viewModel.Posts = posts; ViewBag.FastShare = fastShares; viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar, Request.Location()); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.ListItem, Request.Location()); PostService.SolvePostsCategory(posts.Data); foreach (var item in posts.Data) { item.ModifyDate = item.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); } return(View(viewModel)); }
/// <summary> /// 首页 /// </summary> /// <param name="postService"></param> /// <param name="categoryService"></param> /// <param name="searchDetailsService"></param> /// <param name="noticeService"></param> /// <param name="postAccessRecordService"></param> /// <param name="fastShareService"></param> public HomeController(IPostService postService, ICategoryService categoryService, ISearchDetailsService searchDetailsService, INoticeService noticeService, IPostAccessRecordService postAccessRecordService, IFastShareService fastShareService) { CategoryService = categoryService; PostService = postService; SearchDetailsService = searchDetailsService; NoticeService = noticeService; PostAccessRecordService = postAccessRecordService; FastShareService = fastShareService; }
public async Task <ActionResult> Index([FromServices] IFastShareService fastShareService) { var banners = AdsService.GetsByWeightedPrice(8, AdvertiseType.Banner).OrderBy(a => Guid.NewGuid()).ToList(); var fastShares = await fastShareService.GetAllFromCacheAsync(s => s.Sort); var postsQuery = PostService.GetQuery(p => p.Status == Status.Published); //准备文章的查询 var posts = await postsQuery.Where(p => !p.IsFixedTop).OrderBy(OrderBy.ModifyDate.GetDisplay() + " desc").ToCachedPagedListAsync <Post, PostDto>(1, 15, MapperConfig); posts.Data.InsertRange(0, postsQuery.Where(p => p.IsFixedTop).OrderByDescending(p => p.ModifyDate).ProjectTo <PostDto>(MapperConfig).ToList()); CheckPermission(posts); var viewModel = await GetIndexPageViewModel(); viewModel.Banner = banners; viewModel.Posts = posts; ViewBag.FastShare = fastShares.ToList(); viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate); viewModel.SidebarAds = AdsService.GetsByWeightedPrice(2, AdvertiseType.SideBar); viewModel.ListAdvertisement = AdsService.GetByWeightedPrice(AdvertiseType.PostList); return(View(viewModel)); }