コード例 #1
0
        public async Task <ActionResult <CityDto[]> > GetCities(
            [FromQuery] bool includeCountry = false,
            [FromQuery] int minPopulation   = 0,
            [FromQuery] int maxPopulation   = 0)
        {
            try
            {
                var cities = await _cityRepo.GetCities(includeCountry, minPopulation, maxPopulation);

                var mappedCities = _mapper.Map <CityDto[]>(cities);

                for (var index = 0; index < mappedCities.Count(); index++)
                {
                    var cityLinks       = CreateLinksForCities(mappedCities[index].CityId);
                    var attractionLinks = CreateLinksForCityAttractions(cities[index]);

                    mappedCities[index].Add(cityLinks, attractionLinks);
                }

                return(Ok(mappedCities));
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
        }
コード例 #2
0
ファイル: CityController.cs プロジェクト: MirkoPralica/WebApi
        public async Task <ActionResult <CityModel[]> > GetCities([FromQuery] bool includeAttractions = false)
        {
            try
            {
                var results = await _cityRepo.GetCities(includeAttractions);

                return(Ok(results));
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
        }
コード例 #3
0
        public IHttpActionResult GetCities()
        {
            var data = cityRepo.GetCities();

            return(Ok(data));
        }
コード例 #4
0
 public IQueryable <CityDTO> GetCities()
 {
     return(_cityRepo.GetCities().Select(CityDTO.Create()));
 }