From a77a9954f1a18172c97817d03915117cf0a12f1f Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Fri, 23 Sep 2016 12:26:15 +0200 Subject: [PATCH] limit book query results --- .../ApiControllers/BookQueryApiController.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Yavsc/ApiControllers/BookQueryApiController.cs b/Yavsc/ApiControllers/BookQueryApiController.cs index b3cbf77a..7819434d 100644 --- a/Yavsc/ApiControllers/BookQueryApiController.cs +++ b/Yavsc/ApiControllers/BookQueryApiController.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging; namespace Yavsc.Controllers { + using System; using Yavsc.Model; using Yavsc.Models; using Yavsc.Models.Booking; @@ -26,13 +27,20 @@ namespace Yavsc.Controllers _logger = loggerFactory.CreateLogger(); } - // GET: api/BookQueryApi + // GET: api/BookQueryApi + /// + /// Book queries, by creation order + /// + /// returned Ids must be lower than this value + /// book queries [HttpGet] - public IEnumerable GetCommands() + public IEnumerable GetCommands(long maxId=long.MaxValue) { var uid = User.GetUserId(); - var result = _context.Commands.Include(c => c.Location) - .Include(c => c.Client).Where(c => c.PerformerId == uid). + var now = DateTime.Now; + + var result = _context.Commands.Include(c => c.Location). + Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now). Select(c => new BookQueryProviderView { Client = new ClientProviderView { UserName = c.Client.UserName, UserId = c.ClientId }, @@ -40,7 +48,9 @@ namespace Yavsc.Controllers EventDate = c.EventDate, Id = c.Id, Previsional = c.Previsional - }); + }). + OrderBy(c=>c.Id). + Take(25); return result; }