public async Task <IActionResult> Update(int id)
        {
            var result = await _shelterService.GetById(id);

            if (result.Success)
            {
                return(View("AddOrUpdate", result.Data));
            }
            else
            {
                ErrorAlert("Bir hata oluştu." + result.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemple #2
0
        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));
            }
        }