public IViewComponentResult Invoke() { var model = new TopBarViewModel(); model.SubscibedSubs.AddRange(_subDao.GetSubsByIds(_contextService.GetSubscribedSubIds()).Select(x => x.Name).OrderBy(x => x)); model.DefaultSubs.AddRange(_subDao.GetSubsByIds(_subDao.GetDefaultSubs()).Select(x => x.Name)); return(View(model)); }
public ActionResult Frontpage(PostsSortBy?sort, PostsTimeFilter?time, int?pageNumber, int?pageSize) { var subs = _contextService.GetSubscribedSubIds(); // if the user is not subscribe to any subs, show the default content. if (subs.Count == 0) { subs = _subDao.GetDefaultSubs(); } if (sort == null) { sort = PostsSortBy.Hot; } if (time == null) { time = PostsTimeFilter.All; } if (pageNumber == null || pageNumber < 1) { pageNumber = 1; } if (pageSize == null) { pageSize = 25; } if (pageSize > 100) { pageSize = 100; } if (pageSize < 1) { pageSize = 1; } var postIds = _postDao.GetPosts(subs, sortby: sort.Value, timeFilter: time.Value, // anonymous users don't see NSFW content. // logged in users only see NSFW if preferences say so. // If they want to see NSFW, they will see all content (SFW/NSFW). nsfw: _userContext.CurrentUser == null ? false : (_userContext.CurrentUser.ShowNsfw ? (bool?)null : false), skip: ((pageNumber - 1) * pageSize), take: pageSize); var model = new SubPostsModel(); model.SortBy = sort.Value; model.TimeFilter = time; if (subs.Any()) // maybe the user hasn't subscribed to any subs? { model.Posts = new PagedList <PostWrapped>(_postWrapper.Wrap(postIds, _userContext.CurrentUser), pageNumber.Value, pageSize.Value, postIds.HasMore); } return(View("Posts", model)); }
public ActionResult Frontpage(PostsSortBy?sort, PostsTimeFilter?time, int?pageNumber, int?pageSize) { var subs = _contextService.GetSubscribedSubIds(); // if the user is not subscribed to any subs, show the default content. if (subs.Count == 0) { subs = _subDao.GetDefaultSubs(); } if (sort == null) { sort = PostsSortBy.Hot; } if (time == null) { time = PostsTimeFilter.All; } if (pageNumber == null || pageNumber < 1) { pageNumber = 1; } if (pageSize == null) { pageSize = 25; } if (pageSize > 100) { pageSize = 100; } if (pageSize < 1) { pageSize = 1; } return(View()); }
public List <Guid> GetSubscribedSubIds() { //todo: optimize return(_userContext.CurrentUser != null? _subDao.GetSubscribedSubsForUser(_userContext.CurrentUser.Id) : _subDao.GetDefaultSubs()); }
public List <string> GetSubscribedSubNames() { // todo: optimize return(_userContext.CurrentUser != null?_subDao.GetSubscribedSubsForUser(_userContext.CurrentUser.UserName).Select(x => x.Name).ToList() : _subDao.GetDefaultSubs().Select(x => x.Name).ToList()); }