public ActionResult <IEnumerable <Operation> > GetAllOperations(IPageable pageable) { _log.LogDebug("REST request to get a page of Operations"); var page = _applicationDatabaseContext.Operations.UsePageable(pageable); var headers = PaginationUtil.GeneratePaginationHttpHeaders(page, HttpContext.Request); return(Ok(page.Content).WithHeaders(headers)); }
public PaginationControl(Pagination pagination, FindAllExam findAllExam) { InitializeComponent(); this.pagination = pagination; this.findAllExam = findAllExam; pageIndexs = PaginationUtil.GetPagingIndexString(pagination); InitializePaginationLabel(); }
public ActionResult <IEnumerable <User> > GetAllUsers(IPageable pageable) { _log.LogDebug("REST request to get a page of Users"); var page = _userManager.Users.UsePageable(pageable); var headers = PaginationUtil.GeneratePaginationHttpHeaders(page, HttpContext.Request); return(Ok(page.Content).WithHeaders(headers)); }
public void ParseLinkResponseHeaderTest() { var queryResult = new QueryResult<CaseFile>(); const string linkHeader = "Link=<https://app.penneo.com/api/v1/casefiles?page=17&per_page=10>; rel=\"next\",<https://app.penneo.com/api/v1/casefiles?page=1&per_page=10>; rel=\"first\",<https://app.penneo.com/api/v1/casefiles?page=15&per_page=10>; rel=\"prev\""; PaginationUtil.ParseRepsonseHeadersForPagination(linkHeader, queryResult); Assert.AreEqual(17, queryResult.NextPage); Assert.AreEqual(15, queryResult.PrevPage); Assert.AreEqual(1, queryResult.FirstPage); }
public ActionResult <IEnumerable <BankAccount> > GetAllBankAccounts(IPageable pageable) { _log.LogDebug("REST request to get a page of BankAccounts"); var page = _applicationDatabaseContext.BankAccounts .Include(bankAccount => bankAccount.User) .UsePageable(pageable); var headers = PaginationUtil.GeneratePaginationHttpHeaders(page, HttpContext.Request); return(Ok(page.Content).WithHeaders(headers)); }
public async Task <IActionResult> Get(int page, int rows) { if (!PaginationUtil.ValidatePagination(page, rows)) { return(BadRequest("Page and rows should be greater than 0")); } page = PaginationUtil.GetNormalizedPage(page); return(Ok(await _bookService.GetAll(page, rows))); }
public IHttpResponse Search(string keyword, int?pageNumber, int?pageSize, string sortName, string sortOrder) { Expression <Func <Role, bool> > predicate = null; if (keyword.Length > 0) { predicate = p => p.Name.Contains(keyword) || p.Remark.Contains(keyword); } // var userList = QueryPaging(_roleService, predicate, pageNumber, pageSize, sortName, sortOrder); return(OkResult(PaginationUtil.ConvertToPagination(userList))); }
/// <summary> /// Find entities based on an input object. /// Returns output with data and metadata /// </summary> public QueryResult <T> FindBy <T>(QueryInput input) where T : Entity { _con.Log("FindBy (" + typeof(T).Name + ")", LogSeverity.Information); var criteria = input.Criteria; var orderBy = input.OrderBy; var offset = input.Offset; var limit = input.Limit; UpdateCriteriaDateTimesToUnix(input); var query = criteria ?? new Dictionary <string, object>(); if (limit.HasValue) { query["limit"] = limit; } if (offset.HasValue) { query["offset"] = offset; } if (orderBy != null) { var sort = string.Join(",", orderBy.Keys); var order = string.Join(",", orderBy.Values); query["sort"] = sort; query["order"] = order; } var output = new QueryResult <T>(); output.Input = input; IEnumerable <T> objects; IRestResponse response; output.Success = _con.ApiConnector.FindBy(query, out objects, out response, input.Page, input.PerPage); output.Objects = objects; output.StatusCode = response.StatusCode; output.ErrorMessage = response.ErrorMessage; if (output.Success) { //Map objects var postProcessor = _con.Setup.GetPostProcessor(typeof(T)); if (postProcessor != null) { output.Objects = (IEnumerable <T>)postProcessor(output.Objects); } //Pagination output.Page = input.Page; output.PerPage = input.PerPage; var linkHeader = response.Headers.FirstOrDefault(x => x.Name.Equals("link", StringComparison.OrdinalIgnoreCase)); if (linkHeader != null && linkHeader.Value != null) { PaginationUtil.ParseRepsonseHeadersForPagination(linkHeader.Value.ToString(), output); } //If no objects were returned, assume that there is no next page - regardless of any returned Link response header if (objects == null || !objects.Any()) { output.NextPage = null; } } return(output); }
public void NextPageIndex(int totalItems, int currentPageIndex, int expectedNextPageIndex) { var pagination = PaginationUtil.Calculate(totalItems, 5, currentPageIndex, 7); Assert.AreEqual(expectedNextPageIndex, pagination.Next); }
public void IndexesCount(int totalItems, int indexesCount, int expectedIndexesCount) { var pagination = PaginationUtil.Calculate(totalItems, 5, 1, indexesCount); Assert.AreEqual(expectedIndexesCount, pagination.Indexes.Count); }
private bool TryExecuteSubCommand(string commandNameLC, CommandArgs args) { switch (commandNameLC) { case "commands": case "cmds": args.Player.SendMessage("Available Sub-Commands:", Color.White); args.Player.SendMessage("/ac blocks", Color.Yellow); args.Player.SendMessage("/ac toggle|switch", Color.Yellow); if (args.Player.Group.HasPermission(AdvancedCircuitsPlugin.ReloadCfg_Permission)) { args.Player.SendMessage("/ac reloadcfg", Color.Yellow); } return(true); case "reloadcfg": if (args.Player.Group.HasPermission(AdvancedCircuitsPlugin.ReloadCfg_Permission)) { this.PluginTrace.WriteLineInfo("Reloading configuration file."); try { this.ReloadConfigurationCallback(); this.PluginTrace.WriteLineInfo("Configuration file successfully reloaded."); if (args.Player != TSPlayer.Server) { args.Player.SendMessage("Configuration file successfully reloaded.", Color.Yellow); } } catch (Exception ex) { this.PluginTrace.WriteLineError( "Reloading the configuration file failed. Keeping old configuration. Exception details:\n{0}", ex ); } } else { args.Player.SendErrorMessage("You do not have the necessary permission to do that."); } return(true); case "blocks": case "ores": case "tiles": int pageNumber; if (!PaginationUtil.TryParsePageNumber(args.Parameters, 1, args.Player, out pageNumber)) { return(true); } PaginationUtil.SendPage( args.Player, pageNumber, new List <string>() { "Copper Ore - OR-Gate", "Silver Ore - AND-Gate", "Gold Ore - XOR-Gate / XOR-Port", "Obsidian - NOT-Gate / NOT-Port", "Iron Ore - Swapper", "Spike - Crossover Bridge", "Glass - Input Port", "Active Stone - Active Stone and Block Activator", "Adamantite Ore - Wireless Transmitter" }, new PaginationUtil.Settings { HeaderFormat = "Advanced Circuits Special Blocks (Page {0} of {1})", HeaderTextColor = Color.Lime, LineTextColor = Color.LightGray, MaxLinesPerPage = 4, } ); return(true); case "toggle": case "switch": args.Player.SendInfoMessage("Place or destroy a wire on the component you want to toggle."); if (args.Parameters.Count > 3) { args.Player.SendErrorMessage("Proper syntax: /ac switch [state] [+p]"); args.Player.SendInfoMessage("Type /ac switch help to get more help to this command."); return(true); } bool persistentMode = false; bool?newState = null; if (args.Parameters.Count > 1) { int newStateRaw; if (int.TryParse(args.Parameters[1], out newStateRaw)) { newState = (newStateRaw == 1); } persistentMode = args.ContainsParameter("+p", StringComparison.InvariantCultureIgnoreCase); } CommandInteraction interaction = this.StartOrResetCommandInteraction(args.Player); interaction.DoesNeverComplete = persistentMode; interaction.TileEditCallback = (player, editType, blockType, location, blockStyle) => { if ( editType != TileEditType.PlaceTile || editType != TileEditType.PlaceWall || editType != TileEditType.DestroyWall || editType != TileEditType.PlaceActuator ) { CommandInteractionResult result = new CommandInteractionResult { IsHandled = true, IsInteractionCompleted = true }; Tile tile = TerrariaUtils.Tiles[location]; if ( TShock.CheckTilePermission(args.Player, location.X, location.Y) || ( this.PluginCooperationHandler.IsProtectorAvailable && this.PluginCooperationHandler.Protector_CheckProtected(args.Player, location, false) ) ) { player.SendErrorMessage("This object is protected."); player.SendTileSquare(location, 1); return(result); } BlockType hitBlockType = (BlockType)tile.type; if (tile.active() && hitBlockType == BlockType.ActiveStone) { if (newState == null || newState == false) { TerrariaUtils.Tiles.SetBlock(location, BlockType.InactiveStone); } else { args.Player.SendTileSquare(location); } } else if (hitBlockType == BlockType.InactiveStone) { if (tile.active() && newState == null || newState == true) { TerrariaUtils.Tiles.SetBlock(location, BlockType.ActiveStone); } else { args.Player.SendTileSquare(location); } } else if (tile.active() && TerrariaUtils.Tiles.IsMultistateObject(hitBlockType)) { ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location); bool currentState = TerrariaUtils.Tiles.ObjectHasActiveState(measureData); if (newState == null) { newState = !TerrariaUtils.Tiles.ObjectHasActiveState(measureData); } if (currentState != newState.Value) { TerrariaUtils.Tiles.SetObjectState(measureData, newState.Value); } else { args.Player.SendTileSquare(location); } } else if ( hitBlockType == AdvancedCircuits.BlockType_ORGate || hitBlockType == AdvancedCircuits.BlockType_ANDGate || hitBlockType == AdvancedCircuits.BlockType_XORGate ) { if ( TShock.CheckTilePermission(args.Player, location.X, location.Y) || ( this.PluginCooperationHandler.IsProtectorAvailable && this.PluginCooperationHandler.Protector_CheckProtected(args.Player, location, false) )) { player.SendErrorMessage("This gate is protected."); player.SendTileSquare(location); return(result); } PaintColor paint = (PaintColor)TerrariaUtils.Tiles[location].color(); if (paint == AdvancedCircuits.Paint_Gate_TemporaryState) { player.SendErrorMessage("The gate is painted {0}, there's no point in initializing it.", AdvancedCircuits.Paint_Gate_TemporaryState); args.Player.SendTileSquare(location); return(result); } GateStateMetadata gateState; if (!this.WorldMetadata.GateStates.TryGetValue(location, out gateState)) { gateState = new GateStateMetadata(); this.WorldMetadata.GateStates.Add(location, gateState); } List <DPoint> gatePortLocations = new List <DPoint>(AdvancedCircuits.EnumerateComponentPortLocations(location, new DPoint(1, 1))); for (int i = 0; i < 4; i++) { Tile gatePort = TerrariaUtils.Tiles[gatePortLocations[i]]; if (!gatePort.active() || gatePort.type != (int)AdvancedCircuits.BlockType_InputPort) { continue; } if (newState == null) { if (gateState.PortStates[i] == null) { gateState.PortStates[i] = true; } else { gateState.PortStates[i] = !gateState.PortStates[i]; } } else { gateState.PortStates[i] = newState.Value; } } player.SendSuccessMessage("The states of this gate's ports are now:"); this.SendGatePortStatesInfo(args.Player, gateState); args.Player.SendTileSquare(location); } else if (tile.active() && tile.type == (int)AdvancedCircuits.BlockType_InputPort) { foreach (DPoint adjacentTileLocation in AdvancedCircuits.EnumerateComponentPortLocations(location, new DPoint(1, 1))) { Tile adjacentTile = TerrariaUtils.Tiles[adjacentTileLocation]; if (!adjacentTile.active() || !AdvancedCircuits.IsLogicalGate((BlockType)adjacentTile.type)) { continue; } if ( TShock.CheckTilePermission(args.Player, adjacentTileLocation.X, adjacentTileLocation.Y) || ( this.PluginCooperationHandler.IsProtectorAvailable && this.PluginCooperationHandler.Protector_CheckProtected(args.Player, adjacentTileLocation, false) ) ) { player.SendErrorMessage("This gate is protected."); player.SendTileSquare(location); return(result); } PaintColor paint = (PaintColor)TerrariaUtils.Tiles[location].color(); if (paint == AdvancedCircuits.Paint_Gate_TemporaryState) { player.SendErrorMessage("The gate is painted {0}, there's no point in initializing it.", AdvancedCircuits.Paint_Gate_TemporaryState); args.Player.SendTileSquare(location); return(result); } GateStateMetadata gateState; if (!this.WorldMetadata.GateStates.TryGetValue(adjacentTileLocation, out gateState)) { gateState = new GateStateMetadata(); this.WorldMetadata.GateStates.Add(adjacentTileLocation, gateState); } int portIndex; switch (AdvancedCircuits.DirectionFromTileLocations(adjacentTileLocation, location)) { case Direction.Up: portIndex = 0; break; case Direction.Down: portIndex = 1; break; case Direction.Left: portIndex = 2; break; case Direction.Right: portIndex = 3; break; default: return(result); } if (newState == null) { if (gateState.PortStates[portIndex] == null) { gateState.PortStates[portIndex] = true; } else { gateState.PortStates[portIndex] = !gateState.PortStates[portIndex]; } } else { gateState.PortStates[portIndex] = newState.Value; } player.SendSuccessMessage("The states of this gate's ports are now:"); this.SendGatePortStatesInfo(args.Player, gateState); args.Player.SendTileSquare(location); return(result); } player.SendErrorMessage(string.Format( "The state of \"{0}\" can not be changed.", TerrariaUtils.Tiles.GetBlockTypeName(hitBlockType) )); player.SendTileSquare(location); } return(result); } return(new CommandInteractionResult { IsHandled = false, IsInteractionCompleted = false }); }; interaction.TimeExpiredCallback = (player) => { player.SendErrorMessage("Waited too long, no component will be toggled."); }; args.Player.SendSuccessMessage("Hit an object to change its state."); return(true); } return(false); }
/// <summary> /// 查询分页 /// </summary> /// <typeparam name="TEntity">数据实体</typeparam> /// <param name="service">服务接口</param> /// <param name="predicate">筛选条件</param> /// <param name="pageNumber">页码</param> /// <param name="pageSize">页大小</param> /// <param name="sortName">排序名称</param> /// <param name="sortOrder">排序方式</param> /// <returns></returns> protected Pagination <TEntity> QueryPaging <TEntity>(IService <TEntity> service, Expression <Func <TEntity, bool> > predicate, int?pageNumber, int?pageSize, string sortName, string sortOrder) where TEntity : IEntity { return(PaginationUtil.QueryPaging(service, predicate, pageNumber, pageSize, sortName, sortOrder)); }
/// <summary> /// 查询分页 /// </summary> /// <typeparam name="TEntity">数据实体</typeparam> /// <param name="service">服务接口</param> /// <param name="predicate">筛选条件</param> /// <param name="pageNumber">页码</param> /// <param name="pageSize">页大小</param> /// <param name="sortOrder">排序方式</param> /// <param name="orderSelector">排序选择委托</param> /// <returns></returns> protected Pagination <TEntity> QueryPaging <TEntity>(IService <TEntity> service, Expression <Func <TEntity, bool> > predicate, int?pageNumber, int?pageSize, string sortOrder, Func <IQueryable <TEntity>, OrderByFlag, IQueryable <TEntity> > orderSelector) where TEntity : IEntity { return(PaginationUtil.QueryPaging(service, predicate, pageNumber, pageSize, sortOrder, orderSelector)); }
public static List <IPagination> PrepareLinks( int TotalPages, string RootUrl, int PageNumber, int PageSize, int TotalRecords, bool isFilter, string FilterUrl, string DefaultUrl, string FilterPaginationUrl, string DefaultPaginationUrl, PaginationUtil.Types type) { var _list = new List <IPagination>(); int firstbound = 0; int lastbound = 0; string ToolTip = ""; var Links = PaginationUtil.preparePagination(TotalPages, 7, PageNumber, type); if (Links.Count > 0) { int i = 0; string LinkURL = ""; foreach (int Item in Links) { firstbound = ((Item - 1) * PageSize) + 1; lastbound = firstbound + PageSize - 1; if (lastbound > TotalRecords) { lastbound = TotalRecords; } ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + TotalRecords + " records"; // url settings // normal search if (Item == 1) { if (isFilter) { LinkURL = FilterUrl; } else { LinkURL = DefaultUrl; } } else { if (isFilter) { LinkURL = UtilityBLL.Add_pagenumber(FilterPaginationUrl, Item.ToString()); } else { LinkURL = UtilityBLL.Add_pagenumber(DefaultPaginationUrl, Item.ToString()); } } string _css = ""; if (Item == PageNumber) { _css = "active"; } _list.Add(new IPagination() { css = _css, id = Item, url = LinkURL, tooltip = ToolTip }); } } return(_list); }