Exemplo n.º 1
0
        private async Task <CountryResponse> CreateCountryWithCitiesResponse(Country country)
        {
            if (country != null)
            {
                var cityList = await _citiesRepo.GetByCountryIdAsync(country.Id);

                var cities = new List <CityResponse>();

                foreach (var city in cityList)
                {
                    cities.Add(CreateCityResponse(city));
                }

                return(new CountryResponse(country.Id, country.Name, country.Code, cities.ToImmutableList()));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Retrieve cities for the country id
        /// </summary>
        /// <param name="countryId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ApiResponse <CityListResponse> > GetCitiesByCountryIdAsync(int countryId, CancellationToken cancellationToken = default)
        {
            var responseModel = new ApiResponse <CityListResponse>();

            var countryCities = await _citiesRepo.GetByCountryIdAsync(countryId);

            if (!countryCities.Any())
            {
                return(responseModel);
            }

            var cities = countryCities.OrderBy(c => c.Name);

            var cityList = new List <CityResponse>();

            foreach (var city in cities)
            {
                cityList.Add(CreateCityResponse(city));
            }

            responseModel.Data = new CityListResponse(cityList.ToImmutableList(), cityList.Count);

            return(responseModel);
        }