Ejemplo n.º 1
0
        public IActionResult AddCity(CityWithoutPointsOfInterestDto city)
        {
            var cityToAdd = _mapper.Map <City>(city);
            var res       = _cityRepository.Add(cityToAdd);

            if (res)
            {
                return(StatusCode(201, "Success"));
            }
            return(StatusCode(500, "Error while saving"));
        }
Ejemplo n.º 2
0
        public IActionResult GetCity(int id, bool includePointsOfInterest = false)
        {
            //var cityToReturn = CitiesDataStore.Current.Cities
            //    .FirstOrDefault(c => c.Id == id);
            //if (cityToReturn == null)
            //{
            //    return NotFound();
            //}
            //return Ok(cityToReturn);

            var city = _cityInfoRepository.GetCity(id, includePointsOfInterest);

            if (city == null)
            {
                return(NotFound());
            }

            if (includePointsOfInterest)
            {
                var cityResult = new CityDto()
                {
                    Id          = city.Id,
                    Name        = city.Name,
                    Description = city.Description
                };

                foreach (var poi in city.PointsOfInterest)
                {
                    cityResult.PointsOfInterest.Add(new PointOfInterestDto()
                    {
                        Id          = poi.Id,
                        Name        = poi.Name,
                        Description = poi.Description
                    });
                }
                return(Ok(cityResult));
            }

            var cityWithoutPointsOfInterestResult =
                new CityWithoutPointsOfInterestDto()
            {
                Id          = city.Id,
                Name        = city.Name,
                Description = city.Description
            };

            return(Ok(cityWithoutPointsOfInterestResult));
        }
Ejemplo n.º 3
0
        public IActionResult GetCity(int id, bool includePointOfInterest = false)
        {
            var city = this.FindCity(id, includePointOfInterest);

            if (city == null)
            {
                return(NotFound());
            }

            if (includePointOfInterest)
            {
                return(Ok(city));
            }
            else
            {
                return(Ok(CityWithoutPointsOfInterestDto.From(city)));
            }
        }
Ejemplo n.º 4
0
        public IActionResult GetCity(int id, bool includePointsOfInterest = false)
        {
            var city = _cityInfoRepository.GetCity(id, includePointsOfInterest);

            if (city == null)
            {
                return(NotFound());
            }

            if (includePointsOfInterest)
            {
                var cityResult = _mapper.Map <CityDto>(city);
                return(Ok(cityResult));
            }

            var cityWithoutPointsOfInterestResult = new CityWithoutPointsOfInterestDto();

            return(Ok(cityWithoutPointsOfInterestResult));
        }
Ejemplo n.º 5
0
        public IActionResult GetCity(int id, bool includePointsOfInterest = false)
        {
            var city = _cityInfoRepository.GetCity(id, includePointsOfInterest);

            if (city == null)
            {
                return(NotFound());
            }

            if (includePointsOfInterest)
            {
                var cityResult = new CityDto()
                {
                    Id          = city.Id,
                    Description = city.Description,
                    Name        = city.Name
                };

                foreach (var poi in city.PointsOfInterest)
                {
                    cityResult.PointsOfInterest.Add(
                        new PointOfInterestDto()
                    {
                        Id          = poi.Id,
                        Description = poi.Description,
                        Name        = poi.Name
                    });
                }

                return(Ok(cityResult));
            }

            var cityWithoutPointsOfInterest = new CityWithoutPointsOfInterestDto()
            {
                Id          = city.Id,
                Description = city.Description,
                Name        = city.Name
            };

            return(Ok(cityWithoutPointsOfInterest));
        }
Ejemplo n.º 6
0
        //[Route("[action]")]
        public async Task <IActionResult> GetCityDataTest(int id, bool includeRelations = false)
        {
            if (_cityControllerParameters_Object._use_Lazy_Loading_On_City_Controller)
            {
                if (false == includeRelations)
                {
                    _repositoryWrapper.CityInfoRepositoryWrapper.DisableLazyLoading();

                    var cityEntity = await _repositoryWrapper.CityInfoRepositoryWrapper.FindOne(id);

                    if (null == cityEntity)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        if (_cityControllerParameters_Object._show_Empty_Related_Date_Fields)
                        {
                            CityDto CityDto_Object = _mapper.Map <CityDto>(cityEntity);
                            return(Ok(CityDto_Object));
                        }
                        else
                        {
                            CityWithoutPointsOfInterestDto CityDto_Object = _mapper.Map <CityWithoutPointsOfInterestDto>(cityEntity);
                            return(Ok(CityDto_Object));
                        }
                    }
                }
                else  // true == includeRelations
                {
                    _repositoryWrapper.CityInfoRepositoryWrapper.EnableLazyLoading();

                    var cityEntity = await _repositoryWrapper.CityInfoRepositoryWrapper.FindOne(id);

                    if (null == cityEntity)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        CityDto CityDto_Object = _mapper.Map <CityDto>(cityEntity);
                        if (_cityControllerParameters_Object._show_Cyclic_Data)
                        {
                            return(Ok(cityEntity));
                        }
                        else
                        {
                            return(Ok(CityDto_Object));
                        }
                    }
                }
            }
            else  // !_use_Lazy_Loading_On_City_Controller
            {
                _repositoryWrapper.CityInfoRepositoryWrapper.DisableLazyLoading();

                if (false == includeRelations)
                {
                    var cityEntity = await _repositoryWrapper.CityInfoRepositoryWrapper.GetCity(id, includeRelations);

                    if (null == cityEntity)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        if (_cityControllerParameters_Object._show_Empty_Related_Date_Fields)
                        {
                            var CityDto_Object = _mapper.Map <CityDto>(cityEntity);
                            return(Ok(CityDto_Object));
                        }
                        else
                        {
                            var CityDto_Object = _mapper.Map <CityWithoutPointsOfInterestDto>(cityEntity);
                            return(Ok(CityDto_Object));
                        }
                    }
                }
                else  // true == includeRelations
                {
                    var cityEntity = await _repositoryWrapper.CityInfoRepositoryWrapper.GetCity(id, includeRelations);

                    if (null == cityEntity)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        CityDto CityDto_Object = _mapper.Map <CityDto>(cityEntity);

                        if (_cityControllerParameters_Object._show_Cyclic_Data)
                        {
                            return(Ok(cityEntity));
                        }
                        else
                        {
                            return(Ok(CityDto_Object));
                        }
                    }
                }
            }
        }