Example #1
0
        public IActionResult UpdatePointsOfInteres(int idCity, int id, [FromBody] PointsOfInteresDTO pointOfInteres)
        {
            if (pointOfInteres == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            // var city = CityDataStore.Current.Cities.FirstOrDefault(x => x.Id == idCity);

            var city = _cityInfoRepository.CityExist(idCity);

            if (!city)
            {
                return(NotFound());
            }

            var pointsOfInteresObj = _cityInfoRepository.GetPointOfInterestForCity(idCity, id);

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


            AutoMapper.Mapper.Map(pointOfInteres, pointsOfInteresObj);

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "Ha ocurrido un problema al guardar."));
            }

            return(NoContent());
        }
Example #2
0
        public IActionResult CreationPointsOfInteres(int idCity, [FromBody] PointsOfInteresDTO pointOfInteres)
        {
            if (pointOfInteres == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            // var city = CityDataStore.Current.Cities.FirstOrDefault(x => x.Id == idCity);
            var city = _cityInfoRepository.CityExist(idCity);


            if (!city)
            {
                return(NotFound());
            }

            var maxPointOfInteres = CityDataStore.Current.Cities.SelectMany(x => x.PointsOfInteres).Max(p => p.Id);

            var finalPointOfInteres = AutoMapper.Mapper.Map <PointOfInterest>(pointOfInteres);

            _cityInfoRepository.AddPointOfInterestForCity(idCity, finalPointOfInteres);
            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "Ha ocurrido un problema al guardar."));
            }


            var finalPointOfInteresReturn = AutoMapper.Mapper.Map <PointsOfInteresDTO>(finalPointOfInteres);

            return(CreatedAtRoute("CreationPointsOfInteres", new { idCity = idCity, id = finalPointOfInteresReturn.Id }, finalPointOfInteresReturn));
        }