public async Task <IActionResult> Index(PetListParameters petListParameters, int p = 1) { var result = await _genusService.List(); if (result.Success) { ViewBag.Categories = result.Data; } var response = await _petApiService.List(petListParameters, p); if (response.Success) { var dataCount = await _petApiService.GetPetCount(); var dtoList = new StaticPagedList <PetDto>(response.Data, p, 21, dataCount.Data); return(View(dtoList)); } else { return(View(new PagedList <PetDto>(new List <PetDto>(), p, StaticVars.PaginationPageSize))); } }
public async Task <IDataResult <List <PetDto> > > List(PetListParameters petListParameters, int currentPage = 1, bool getImages = true) { var query = new Dictionary <string, string> { ["p"] = currentPage.ToString() }; if (petListParameters != null) { if (petListParameters.GenusId.HasValue) { query.Add("genusId", petListParameters.GenusId.Value.ToString()); } if (petListParameters.SpeciesId.HasValue) { query.Add("speciesId", petListParameters.SpeciesId.Value.ToString()); } if (!string.IsNullOrWhiteSpace(petListParameters.SearchTerm)) { query.Add("searchTerm", petListParameters.SearchTerm.ToString()); } } var response = await _httpClient.GetAsync(QueryHelpers.AddQueryString("getPets", query)); if (response.IsSuccessStatusCode) { var dto = JsonConvert.DeserializeObject <List <PetDto> >(await response.Content.ReadAsStringAsync()); if (getImages) { dto.ForEach(x => x.Images = GetPetImages(x.PetId).Result); } dto.ForEach(x => x.ShelterName = _shelterApiService.GetById(x.ShelterId.Value).Result.Data.ShelterName); return(new DataResult <List <PetDto> >(dto, true, response.StatusCode)); } else { return(new DataResult <List <PetDto> >(null, false, response.StatusCode)); } }