public void List(int page = 1) { var list = EssentialsPlugin.Instance.Whitelist.Allowed; var col = Server.Instance.Colors; int maxpage = PaginationUtilities.DeterminePageCount(list.Count); if (page < 1 || page > maxpage) { Sender.SendMessage($"This page is empty. Try pages {1} - {maxpage}", col.Error); } else { Sender.SendInfoMessage($"Page {page}/{maxpage} of whitelist"); //The method takes a zero-based page number, but the one provided by the user is 1-based. foreach (var ip in PaginationUtilities.Paginate(list, page - 1)) { Sender.SendInfoMessage($"- {ip}"); } if (page > 1) { Sender.SendFormattedMessage($"> Use {Color.IndianRed}/whitelist {Color.LightGray}list {page - 1}{col.Info} for the previous page.", col.Info); } if (page < maxpage) { Sender.SendFormattedMessage($"> Use {Color.IndianRed}/whitelist {Color.LightGray}list {page + 1}{col.Info} for the next page.", col.Info); } } }
public static Negotiator FindBy(Request request, Negotiator negotiate, IGenericRepository <T> _repository) { List <Tuple <string, string> > headers = new List <Tuple <string, string> >(); PaginatedResponse <T> response; var paginationInfo = GetPaginationInfo(request); var reason = PaginationUtilities.CheckPaginationInfo(paginationInfo); if (!string.IsNullOrEmpty(reason)) { return(negotiate .WithHeaders(headers.ToArray()) .WithStatusCode(HttpStatusCode.BadRequest) .WithReasonPhrase(reason)); } response = _repository.FindBy(paginationInfo, GetSortingInfo(request), null); if (response.Items == null && !response.PaginationInfo.IsCurrentPageNumberValid()) { reason = "Requested page not allowed"; return(negotiate .WithHeaders(headers.ToArray()) .WithStatusCode(HttpStatusCode.BadRequest) .WithReasonPhrase(reason)); } headers.Add(PaginationUtilities.GetLinks(request.Url.SiteBase + request.Url.Path, response.PaginationInfo, string.Format("Sort={0}", response.SortingInfo.Property))); headers.AddRange(PaginationUtilities.GetPaginatedHeaderInfo(response.PaginationInfo)); if (!response.SortingInfo.IsValid) { return(negotiate .WithHeaders(headers.ToArray()) .WithStatusCode(HttpStatusCode.BadRequest) .WithReasonPhrase(response.SortingInfo.Reason)); } return(negotiate .WithModel(response.Items) .WithHeaders(headers.ToArray()) .WithStatusCode(PaginationUtilities.IsPartialResult(response.PaginationInfo) ? HttpStatusCode.PartialContent : HttpStatusCode.OK)); }