public List<PrivateMessage> GetPrivateMessages(User user, PrivateMessageBoxType boxType, int pageIndex, out PagerContext pagerContext) { var total = PrivateMessageRepository.GetBoxCount(user.UserID, boxType); var pageSize = SettingsManager.Current.TopicsPerPage; var startRow = ((pageIndex - 1) * pageSize) + 1; var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return PrivateMessageRepository.GetPrivateMessages(user.UserID, boxType, startRow, pageSize); }
public List<Topic> GetTopics(User user, int pageIndex, out PagerContext pagerContext) { var pageSize = _settingsManager.Current.TopicsPerPage; var startRow = ((pageIndex - 1) * pageSize) + 1; var topics = _favoriteTopicRepository.GetFavoriteTopics(user.UserID, startRow, pageSize); var topicCount = _favoriteTopicRepository.GetFavoriteTopicCount(user.UserID); var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(topicCount) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return topics; }
public List<Topic> GetTopics(User viewingUser, User postUser, bool includeDeleted, int pageIndex, out PagerContext pagerContext) { var nonViewableForumIDs = _forumService.GetNonViewableForumIDs(viewingUser); var pageSize = _settingsManager.Current.TopicsPerPage; var startRow = ((pageIndex - 1) * pageSize) + 1; var topics = _topicRepository.GetTopicsByUser(postUser.UserID, includeDeleted, nonViewableForumIDs, startRow, pageSize); var topicCount = _topicRepository.GetTopicCountByUser(postUser.UserID, includeDeleted, nonViewableForumIDs); var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(topicCount) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return topics; }
public List<Post> GetPosts(Topic topic, int lastLoadedPostID, bool includeDeleted, out PagerContext pagerContext) { var allPosts = _postRepository.Get(topic.TopicID, includeDeleted); var lastIndex = allPosts.FindIndex(p => p.PostID == lastLoadedPostID); if (lastIndex < 0) throw new Exception(String.Format("PostID {0} is not a part of TopicID {1}.", lastLoadedPostID, topic.TopicID)); var posts = allPosts.Skip(lastIndex + 1).ToList(); var pageSize = _settingsManager.Current.PostsPerPage; var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(allPosts.Count) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = totalPages, PageSize = pageSize }; return posts; }
public List<Topic> GetTopics(Forum forum, bool includeDeleted, int pageIndex, out PagerContext pagerContext) { var pageSize = _settingsManager.Current.TopicsPerPage; var startRow = ((pageIndex - 1) * pageSize) + 1; var topics = _topicRepository.Get(forum.ForumID, includeDeleted, startRow, pageSize); int topicCount; if (includeDeleted) topicCount = _topicRepository.GetTopicCount(forum.ForumID, true); else topicCount = forum.TopicCount; var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(topicCount) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return topics; }
public List<Post> GetPosts(Topic topic, bool includeDeleted, int pageIndex, out PagerContext pagerContext) { var pageSize = _settingsManager.Current.PostsPerPage; var startRow = ((pageIndex - 1) * pageSize) + 1; var posts = _postRepository.Get(topic.TopicID, includeDeleted, startRow, pageSize); int postCount; if (includeDeleted) postCount = _postRepository.GetReplyCount(topic.TopicID, true); else postCount = topic.ReplyCount + 1; var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(postCount) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return posts; }
public List<Topic> GetTopics(string searchTerm, SearchType searchType, User user, bool includeDeleted, int pageIndex, out PagerContext pagerContext) { var nonViewableForumIDs = _forumService.GetNonViewableForumIDs(user); var pageSize = _settingsManager.Current.TopicsPerPage; var startRow = ((pageIndex - 1) * pageSize) + 1; var topicCount = 0; List<Topic> topics; if (String.IsNullOrEmpty(searchTerm)) topics = new List<Topic>(); else topics = _searchRepository.SearchTopics(searchTerm, nonViewableForumIDs, searchType, startRow, pageSize, out topicCount); var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(topicCount) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return topics; }
private static TopicContainer ComposeTopicContainer(Topic topic, Forum forum, ForumPermissionContext permissionContext, bool isSubscribed, List<Post> posts, PagerContext pagerContext, bool isFavorite, Dictionary<int, string> signatures, Dictionary<int, int> avatars, List<int> votedPostIDs, DateTime? lastreadTime) { return new TopicContainer { Forum = forum, Topic = topic, Posts = posts, PagerContext = pagerContext, PermissionContext = permissionContext, IsSubscribed = isSubscribed, IsFavorite = isFavorite, Signatures = signatures, Avatars = avatars, VotedPostIDs = votedPostIDs, LastReadTime = lastreadTime}; }
public static MvcHtmlString PagerLinks(this HtmlHelper htmlHelper, string controllerName, string actionName, PagerContext pagerContext, string firstPage, string previousPage, string nextPage, string lastPage, string moreText, string cssClass, string moreTextCssClass, string currentPageCssClass, Dictionary<string, object> routeParameters) { if (pagerContext == null) return null; var builder = new StringBuilder(); if (String.IsNullOrEmpty(controllerName) || String.IsNullOrEmpty(actionName)) throw new Exception("controllerName and actionName must be specified for PageLinks."); if (pagerContext.PageCount <= 1) return MvcHtmlString.Create(String.Empty); if (String.IsNullOrEmpty(cssClass)) builder.Append("<ul class=\"pagination\">"); else builder.Append(String.Format("<ul class=\"pagination {0}\">", cssClass)); if (String.IsNullOrEmpty(moreTextCssClass)) builder.Append(String.Format("<li><span>{0}</span></li>", moreText)); else builder.Append(String.Format("<li class=\"{0}\"><span>{1}</span></li>", moreTextCssClass, moreText)); if (pagerContext.PageIndex != 1) { // first page link builder.Append("<li>"); var firstRouteDictionary = new RouteValueDictionary(new {controller = controllerName, action = actionName, page = 1}); if (routeParameters != null) foreach (var item in routeParameters) firstRouteDictionary.Add(item.Key, item.Value); var firstLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, firstRouteDictionary, new Dictionary<string, object> { { "title", firstPage }, { "class", "glyphicon glyphicon-step-backward" } }); builder.Append(firstLink); builder.Append("</li>"); if (pagerContext.PageIndex > 2) { // previous page link var previousIndex = pagerContext.PageIndex - 1; builder.Append("<li>"); var previousRouteDictionary = new RouteValueDictionary(new {controller = controllerName, action = actionName, page = previousIndex}); if (routeParameters != null) foreach (var item in routeParameters) previousRouteDictionary.Add(item.Key, item.Value); var previousLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, previousRouteDictionary, new Dictionary<string, object> { { "title", previousPage }, { "rel", "prev" }, { "class", "glyphicon glyphicon-chevron-left" } }); builder.Append(previousLink); builder.Append("</li>"); } } // calc low and high limits for numeric links var low = pagerContext.PageIndex - 1; var high = pagerContext.PageIndex + 3; if (low < 1) low = 1; if (high > pagerContext.PageCount) high = pagerContext.PageCount; if (high - low < 5) while ((high < low + 4) && high < pagerContext.PageCount) high++; if (high - low < 5) while ((low > high - 4) && low > 1) low--; for (var x = low; x < high + 1; x++) { // numeric links if (x == pagerContext.PageIndex) { if (String.IsNullOrEmpty(currentPageCssClass)) builder.Append(String.Format("<li><span class=\"active\">{0} of {1}</span></li>", x, pagerContext.PageCount)); else builder.Append(String.Format("<li class=\"active {0}\"><span>{1} of {2}</span></li>", currentPageCssClass, x, pagerContext.PageCount)); } else { builder.Append("<li>"); var numericRouteDictionary = new RouteValueDictionary {{"controller", controllerName}, {"action", actionName}, {"page", x}}; if (routeParameters != null) foreach (var item in routeParameters) numericRouteDictionary.Add(item.Key, item.Value); builder.Append(htmlHelper.RouteLink(x.ToString(), numericRouteDictionary)); builder.Append("</li>"); } } if (pagerContext.PageIndex != pagerContext.PageCount) { if (pagerContext.PageIndex < pagerContext.PageCount - 1) { // next page link var nextIndex = pagerContext.PageIndex + 1; builder.Append("<li>"); var nextRouteDictionary = new RouteValueDictionary(new {controller = controllerName, action = actionName, page = nextIndex}); if (routeParameters != null) foreach (var item in routeParameters) nextRouteDictionary.Add(item.Key, item.Value); var nextLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, nextRouteDictionary, new Dictionary<string, object> { { "title", nextPage }, { "rel", "next" }, { "class", "glyphicon glyphicon-chevron-right" } }); builder.Append(nextLink); builder.Append("</li>"); } // last page link builder.Append("<li>"); var lastRouteDictionary = new RouteValueDictionary(new {controller = controllerName, action = actionName, page = pagerContext.PageCount}); if (routeParameters != null) foreach (var item in routeParameters) lastRouteDictionary.Add(item.Key, item.Value); var lastLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, lastRouteDictionary, new Dictionary<string, object> { { "title", lastPage }, { "class", "glyphicon glyphicon-step-forward" } }); builder.Append(lastLink); builder.Append("</li>"); } builder.Append("</ul>"); return MvcHtmlString.Create(builder.ToString()); }
public static MvcHtmlString PagerLinks(this HtmlHelper htmlHelper, string controllerName, string actionName, PagerContext pagerContext, int low, int high, string id, string cssClass, string moreTextCssClass, string currentPageCssClass) { return PagerLinks(htmlHelper, controllerName, actionName, pagerContext, low, high, id, Resources.First, Resources.Previous, Resources.Next, Resources.Last, Resources.More + ":", cssClass, moreTextCssClass, currentPageCssClass); }
public static MvcHtmlString PagerLinks(this HtmlHelper htmlHelper, string controllerName, string actionName, PagerContext pagerContext, string cssClass, string moreTextCssClass, string currentPageCssClass, Dictionary<string, object> routeParameters) { return PagerLinks(htmlHelper, controllerName, actionName, pagerContext, Resources.First, Resources.Previous, Resources.Next, Resources.Last, Resources.More + ":", cssClass, moreTextCssClass, currentPageCssClass, routeParameters); }
public static MvcHtmlString PagerLinks(this HtmlHelper htmlHelper, string controllerName, string actionName, PagerContext pagerContext, int low, int high, string id, string firstPage, string previousPage, string nextPage, string lastPage, string moreText, string cssClass, string moreTextCssClass, string currentPageCssClass) { if (pagerContext == null) return null; var builder = new StringBuilder(); if (String.IsNullOrEmpty(controllerName) || String.IsNullOrEmpty(actionName)) throw new Exception("controllerName and actionName must be specified for PageLinks."); if (pagerContext.PageCount <= 1) return MvcHtmlString.Create(String.Empty); if (String.IsNullOrEmpty(cssClass)) builder.Append("<ul class=\"pagination\">"); else builder.Append(String.Format("<ul class=\"pagination {0}\">", cssClass)); if (String.IsNullOrEmpty(moreTextCssClass)) builder.Append(String.Format("<li><span>{0}</span></li>", moreText)); else builder.Append(String.Format("<li class=\"{0}\"><span>{1}</span></li>", moreTextCssClass, moreText)); if (pagerContext.PageIndex != 1 && low != 1) { // first page link builder.Append("<li>"); var firstLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, new RouteValueDictionary(new { controller = controllerName, action = actionName, page = 1, id }), new Dictionary<string, object> { { "title", firstPage }, { "class", "glyphicon glyphicon-step-backward" } }); builder.Append(firstLink); builder.Append("</li>"); if (pagerContext.PageIndex > 2 && !(low < pagerContext.PageIndex)) { // previous page link var previousIndex = pagerContext.PageIndex - 1; builder.Append("<li>"); var previousLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, new RouteValueDictionary(new { controller = controllerName, action = actionName, page = previousIndex, id }), new Dictionary<string, object> { { "title", previousPage }, { "rel", "prev" }, { "class", "glyphicon glyphicon-chevron-left" } }); builder.Append(previousLink); builder.Append("</li>"); } } // calc low and high limits for numeric links var calcLow = pagerContext.PageIndex - 1; var calcHigh = pagerContext.PageIndex + 3; if (calcLow < 1) calcLow = 1; if (calcHigh > pagerContext.PageCount) calcHigh = pagerContext.PageCount; if (calcHigh - calcLow < 5) while ((calcHigh < calcLow + 4) && calcHigh < pagerContext.PageCount) calcHigh++; if (calcHigh - calcLow < 5) while ((calcLow > calcHigh - 4) && calcLow > 1) calcLow--; var isRangeRendered = false; for (var x = calcLow; x < calcHigh + 1; x++) { // numeric links if (x >= low && x <= high) { if (!isRangeRendered) { isRangeRendered = true; if (String.IsNullOrEmpty(currentPageCssClass)) builder.Append(String.Format("<li class=\"active\"><span>{0}-{1} of {2}</span></li>", low, high, pagerContext.PageCount)); else builder.Append(String.Format("<li class=\"active {0}\"><span>{1}-{2} of {3}</span></li>", currentPageCssClass, low, high, pagerContext.PageCount)); } } else { builder.Append("<li>"); builder.Append(htmlHelper.RouteLink(x.ToString(), new { controller = controllerName, action = actionName, page = x, id })); builder.Append("</li>"); } } if (pagerContext.PageIndex != pagerContext.PageCount && high < pagerContext.PageCount) { if (pagerContext.PageIndex < pagerContext.PageCount - 1) { // next page link var nextIndex = pagerContext.PageIndex + 1; builder.Append("<li>"); var nextLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, new RouteValueDictionary(new { controller = controllerName, action = actionName, page = nextIndex, id }), new Dictionary<string, object> { { "title", nextPage }, { "rel", "next" }, { "class", "glyphicon glyphicon-chevron-right" } }); builder.Append(nextLink); builder.Append("</li>"); } // last page link builder.Append("<li>"); var lastLink = HtmlHelper.GenerateRouteLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, "", null, new RouteValueDictionary(new { controller = controllerName, action = actionName, page = pagerContext.PageCount, id }), new Dictionary<string, object> { { "title", lastPage }, { "class", "glyphicon glyphicon-step-forward" } }); builder.Append(lastLink); builder.Append("</li>"); } builder.Append("</ul>"); return MvcHtmlString.Create(builder.ToString()); }
public List<ErrorLogEntry> GetErrors(int pageIndex, int pageSize, out PagerContext pagerContext) { var startRow = ((pageIndex - 1) * pageSize) + 1; var errors = _errorLogRepository.GetErrors(startRow, pageSize); var errorCount = _errorLogRepository.GetErrorCount(); var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(errorCount) / Convert.ToDouble(pageSize))); pagerContext = new PagerContext { PageCount = totalPages, PageIndex = pageIndex, PageSize = pageSize }; return errors; }