コード例 #1
0
        public IActionResult GetCitiesForProvience(Guid countryId, Guid provienceId)
        {
            if (!_countryRepository.EntityExists(countryId))
            {
                return(NotFound());
            }

            if (!_provienceRepository.EntityExists(provienceId))
            {
                return(NotFound());
            }

            var citiesForProvienceFromRepo = _provienceRepository.GetCitiesForProvience(provienceId);

            var results = Mapper.Map <IEnumerable <CityApiModel> >(citiesForProvienceFromRepo);

            foreach (var cityApiModel in results)
            {
                cityApiModel.MainImageId = _imageRepository.GetMainImageIdForCity(cityApiModel.Id);

                var attractionsFromRepo = _attractionRepository.GetAttractionsForCity(cityApiModel.Id);

                var attractionsAPIModel = Mapper.Map <IEnumerable <AttractionApiModel> >(attractionsFromRepo);

                foreach (var cityAttractionAPIModel in attractionsAPIModel)
                {
                    cityApiModel.Attractions.Add(cityAttractionAPIModel);
                }
            }


            return(Ok(results));
        }
コード例 #2
0
 public IActionResult BlockCountryCreation(Guid id)
 {
     if (_countryRepository.EntityExists(id))
     {
         return(new StatusCodeResult(StatusCodes.Status409Conflict));
     }
     return(NotFound());
 }
コード例 #3
0
        public IActionResult GetProviencesForCountry(Guid countryId)
        {
            if (!_countryRepository.EntityExists(countryId))
            {
                return(NotFound());
            }

            var proviencesForCountryFromRepo = _countryRepository.GetProviencesForCountry(countryId);


            var citiesApiModel = new Dictionary <string, IEnumerable <CityApiModel> >();

            foreach (var provience in proviencesForCountryFromRepo)
            {
                var citiesFromRepo = _provienceRepository.GetCitiesForProvience(provience.Id).Take(5);
                citiesApiModel.Add(provience.Id.ToString(), Mapper.Map <IEnumerable <CityApiModel> >(citiesFromRepo));
            }

            var proviencesApiModel = Mapper.Map <IEnumerable <ProvienceApiModel> >(proviencesForCountryFromRepo);

            foreach (var provienceApiModel in proviencesApiModel)
            {
                foreach (var cityApiModel in citiesApiModel[provienceApiModel.Id.ToString()])
                {
                    provienceApiModel.Cities.Add(cityApiModel);
                }
            }

            var results = proviencesApiModel;

            return(Ok(results));
        }