public async Task <PagedResults <Models.Narudzbenica> > GetNarudzbeniceAsync(CancellationToken ct, PaginigOptions paginigOptions, NarudzbenicaOptions narudzbenicaOptions) { var query = queryForm(null, narudzbenicaOptions.imeZaposleng, narudzbenicaOptions.prezimeZaposlenog, narudzbenicaOptions.statusDostave, narudzbenicaOptions.datumPrijema); var narudzbenice = await query.ToArrayAsync(); if (narudzbenice == null) { return(null); } List <Entities.Narudzbenica> narudzbenicesList = new List <Entities.Narudzbenica>(); foreach (var prom in narudzbenice) { narudzbenicesList.Add(prom.Narudzbenica); } var narudzbenicaMap = _mapper.Map <IEnumerable <Entities.Narudzbenica>, IEnumerable <Models.Narudzbenica> >(narudzbenicesList); var narudzbenicaPagin = narudzbenicaMap.Skip(paginigOptions.Offset.Value).Take(paginigOptions.Limit.Value); return(new PagedResults <Models.Narudzbenica> { Items = narudzbenicaPagin, TotalSize = narudzbenicaMap.Count() }); }
public async Task <ActionResult <IEnumerable <Narudzbenica> > > GetNarudzbeniceAsync(CancellationToken ct, [FromQuery] PaginigOptions paginigOptions, [FromQuery] NarudzbenicaOptions narudzbenicaOptions) { if (!ModelState.IsValid) { return(BadRequest(new ApiError(ModelState))); } paginigOptions.Offset = paginigOptions.Offset ?? 0; paginigOptions.Limit = paginigOptions.Limit ?? 25; var collection = await _narudzbenicaService.GetNarudzbeniceAsync(ct, paginigOptions, narudzbenicaOptions); if (collection == null) { return(NotFound()); } var collectionLink = Link.ToCollection(nameof(GetNarudzbeniceAsync)); var resources = new PagedCollection <Models.Narudzbenica> { Self = collectionLink, Value = collection.Items.ToArray(), Size = collection.TotalSize, Offset = paginigOptions.Offset.Value, Limit = paginigOptions.Limit.Value }; return(Ok(resources)); }