Esempio n. 1
0
        public IActionResult UpdatePointsOfInterest(int cityId, int id, [FromBody] PointOfInterestUpdate pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!_repository.CityExists(cityId))
            {
                return(NotFound());
            }
            var pointOfInterestFromStore = _repository.GetPointOfInterest(cityId, id);

            if (pointOfInterestFromStore == null)
            {
                return(NotFound());
            }
            Mapper.Map(pointOfInterest, pointOfInterestFromStore);
            if (!_repository.Save())
            {
                return(StatusCode(500, "Something was wrong on server"));
            }
            return(NoContent());
        }
        public IActionResult Update(int cityId, int id, PointOfInterestUpdate model)
        {
            if (model.Name.Equals(model.Description, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("Description", "The provided Name and Description must be different");
            }

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

            if (!_repository.IsCityExists(cityId))
            {
                return(NotFound());
            }

            var entity = _repository.GetPointOfInterestForCity(cityId, id);

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

            _mapper.Map(model, entity);
            _repository.UpdatePointOfInterestForCity(cityId, entity);
            return(NoContent());
        }