Beispiel #1
0
        public async Task <CityDto> GetCityByIdAsync(int id)
        {
            var city = await _citiesRepository.FindByIdAsync(id);

            if (city == null)
            {
                throw new ObjectNotFoundException($"City with id {id} does not exist");
            }
            return(_mapper.Map <CityDto>(city));
        }
Beispiel #2
0
        public async Task <IEnumerable <SightDto> > GetAllByCityIdAsync(int cityId)
        {
            var city = await _citiesRepository.FindByIdAsync(cityId);

            if (city == null)
            {
                throw new ObjectNotFoundException($"Sight with id {cityId} does not exist");
            }

            return(_mapper.Map <IEnumerable <SightDto> >(city.Sights));
        }
Beispiel #3
0
        /// <summary>
        /// Retrieve city for the specified id
        /// </summary>
        /// <param name="cityId"></param>
        /// <param name="includeDistricts"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ApiResponse <CityResponse> > GetCityByIdAsync(int cityId, bool includeDistricts = true, CancellationToken cancellationToken = default)
        {
            var responseModel = new ApiResponse <CityResponse>();

            var city = await _citiesRepo.FindByIdAsync(cityId);

            if (city == null)
            {
                responseModel.AddError(ExceptionCreator.CreateNotFoundError(nameof(city), $"city of id {cityId}: not found"));

                return(responseModel);
            }

            responseModel.Data = CreateCityResponse(city);

            return(responseModel);
        }