public async Task <IActionResult> GetCountries(CountryDtoParamters countryDtoParamters, [FromHeader(Name = "Accept")] string mediaType) { if (!_propertyMappingContainer.ValidMappingExistsFor <CountryDto, Country>(countryDtoParamters.OrderBy)) { return(BadRequest("Can't find the fields for sorting")); } if (!_typeHelperService.TypeHasProperties <CountryDto>(countryDtoParamters.Fields)) { return(BadRequest("Can't find the fields on Resource.")); } var pagedList = await _countryRepository.GetCountriesAsync(countryDtoParamters); var countryDto = _mapper.Map <List <CountryDto> >(pagedList); return(Ok()); }
public async Task <PaginatedList <Country> > GetCountriesAsync(CountryDtoParamters paramters) { var query = _myContext.Countries.AsQueryable(); if (!string.IsNullOrEmpty(paramters.EnglishName)) { var englishNameClause = paramters.EnglishName.Trim().ToLowerInvariant(); query = query.Where(x => x.EnglishName.ToLowerInvariant() == englishNameClause); } if (!string.IsNullOrEmpty(paramters.ChineseName)) { var chineseNameClause = paramters.ChineseName.Trim().ToLowerInvariant(); query = query.Where(x => x.ChineseName.ToLowerInvariant() == chineseNameClause); } var count = await query.CountAsync(); var items = await query.Skip(paramters.PageSize *(paramters.PageIndex - 1)).Take(paramters.PageSize).ToListAsync(); return(new PaginatedList <Country>(paramters.PageIndex, paramters.PageSize, count, items)); }