public PagedList <Performance> GetPerformances(PerformancesResourceParameters parameters) { IQueryable <Performance> performances = Enumerable.Empty <Performance>().AsQueryable(); if (parameters.Filter != null) { foreach (var condition in GetPerformancesDictionary(parameters.Filter).Keys) { if (condition) { performances = GetPerformancesDictionary(parameters.Filter)[condition]; } } } else { performances = GetPerformances(); } if (!string.IsNullOrWhiteSpace(parameters.OrderBy)) { var moviePropertyMappingDictionary = _propertyMappingService.GetPropertyMapping <PerformanceDto, Performance>(); performances = performances.ApplySort(parameters.OrderBy, moviePropertyMappingDictionary); } return(PagedList <Performance> .Create(performances, parameters.PageNumber, parameters.PageSize)); }
public IActionResult GetPerformances([FromQuery] PerformancesResourceParameters parameters) { if (!_propertyMappingService.ValidMappingExistsFor <PerformanceDto, Performance>(parameters.OrderBy) || !_propertyCheckerService.TypeHasProperties <PerformanceDto>(parameters.Fields)) { return(BadRequest()); } if (!string.IsNullOrEmpty(parameters.Fields) && !parameters.Fields.Contains("id")) { return(BadRequest()); } var performances = _unitOfWork.Performances.GetPerformances(parameters); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject( _paginationService.CreatePaginationMetadata(performances, parameters))); return(Ok(_dataShapingService.GetShapedCollectionWithLinks(performances, parameters))); }