private string CreateUriParagliderModel(ParagliderModelsSSFP options, RessourceUriType type) { switch (type) { case RessourceUriType.PreviousPage: return(Url.Link("GetAllModelParaglidersAsync", new { PageNumber = options.PageNumber - 1, options.PageSize, options.FilterBy, options.SearchBy, options.Pilotweight })); case RessourceUriType.NextPage: return(Url.Link("GetAllModelParaglidersAsync", new { PageNumber = options.PageNumber + 1, options.PageSize, options.FilterBy, options.SearchBy, options.Pilotweight })); default: return(Url.Link("GetAllModelParaglidersAsync", new { options.PageNumber, options.PageSize, options.FilterBy, options.SearchBy, options.Pilotweight })); } }
public async Task <IReadOnlyCollection <ParagliderModelDto> > GetAllParagliderModelsAsync(ParagliderModelsSSFP options) { var modelparaglider = _paraContext.ParagliderModels //DEFERED EXECUTION .AsNoTracking() .ParagliderModelSearchBy(options.SearchBy, pSize: options.Size, pApprovalNumber: options.ApprovalNumber) .ParagliderModelsSortsBy(options.SortsBy) .FilterParagliderModelBy(options.FilterBy, options.Pilotweight) .Select(p => new ParagliderModelDto // Projection { ID = p.ID, Size = p.Size, MaxWeightPilot = p.MaxWeightPilot, MinWeightPilot = p.MinWeightPilot, ApprovalDate = p.ApprovalDate, ApprovalNumber = p.ApprovalNumber, IsActive = p.IsActive }); options.SetPagingValues(modelparaglider); //Appel de la fonction située dans ParagliderModelsSSFP return(await modelparaglider.ToListAsync()); // Flattening }
public async Task <ActionResult <IReadOnlyCollection <ParagliderModelDto> > > GetAllModelParaglidersAsync([FromQuery] ParagliderModelsSSFP options) { var listModelParaglider = await _ModelParagliderService.GetAllParagliderModelsAsync(options); if (listModelParaglider == null) { return(NotFound("There is no model of paraglider ")); } var previousPageLink = options.HasPrevious ? CreateUriParagliderModel(options, RessourceUriType.PreviousPage) : null; var nextPageLink = options.HasNext ? CreateUriParagliderModel(options, RessourceUriType.NextPage) : null; var paginationMetadata = new { options.TotalCount, options.PageSize, options.PageNumber, options.TotalPages, previousPageLink, nextPageLink }; Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata)); return(Ok(listModelParaglider)); }