public IActionResult UpdatePointOfInterest(int cityId, int interestId, [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }
            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "Description should be different from name.");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

            if (city == null)
            {
                return(NotFound());
            }
            var interestPointFromStore = city.PointOfInterest.FirstOrDefault(interest => interest.Id == interestId);

            if (interestPointFromStore == null)
            {
                return(NotFound());
            }
            interestPointFromStore.Name        = pointOfInterest.Name;
            interestPointFromStore.Description = pointOfInterest.Description;
            return(NoContent());
        }
예제 #2
0
        public IActionResult UpdatePointsOfInterest(int cityId, int pointOfInterestId,
                                                    [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

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

            CityDto city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            PointsOfInterestDto currentPointOfInterest =
                city.PointsOfInterest.FirstOrDefault(i => i.Id == pointOfInterestId);

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

            currentPointOfInterest.Name        = pointOfInterest.Name;
            currentPointOfInterest.Description = pointOfInterest.Description;

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, POIId = currentPointOfInterest.Id },
                                  currentPointOfInterest));
        }
예제 #3
0
        public IActionResult UpdatePointOfInterest(int cityId, int id, [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

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

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            var point = _cityInfoRepository.GetPointOfInterestForCity(cityId, id);

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

            _mapper.Map(pointOfInterest, point);
            _cityInfoRepository.UpdatePointOfInterestForCity(cityId, point);
            _cityInfoRepository.Save();

            return(NoContent());
        }
        public IActionResult UpdatePointOfInterest(int cityId, int pointOfInterestId,
                                                   [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            //var cityToReturn = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

            //if (cityToReturn == null)
            //{
            //    return NotFound();
            //}

            //var pointOfInterestFromStore = cityToReturn.PointsOfInterest.FirstOrDefault(p => p.Id == pointOfInterestId);

            //if (pointOfInterestFromStore == null)
            //{
            //    return NotFound();
            //}

            //pointOfInterestFromStore.Name = pointsOfInterest.Name;
            //pointOfInterestFromStore.Description = pointsOfInterest.Description;

            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

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

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            var pointOfInterestEntity = _cityInfoRepository.GetPointOfInterestForCity(cityId, pointOfInterestId);

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

            _mapper.Map(pointOfInterest, pointOfInterestEntity);

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handline your request."));
            }

            return(NoContent());
        }
예제 #5
0
        public IActionResult PatchPointsOfInterest(int cityId, int pointOfInterestId,
                                                   [FromBody] JsonPatchDocument <PointsOfInterestForUpdateDto> pointOfInterestPatch)
        {
            if (pointOfInterestPatch == null)
            {
                return(BadRequest());
            }

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

            CityDto city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            PointsOfInterestDto currentPointOfInterest =
                city.PointsOfInterest.FirstOrDefault(i => i.Id == pointOfInterestId);

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

            PointsOfInterestForUpdateDto newPointOfInterest =
                new PointsOfInterestForUpdateDto()
            {
                Name        = currentPointOfInterest.Name,
                Description = currentPointOfInterest.Description
            };

            pointOfInterestPatch.ApplyTo(newPointOfInterest, ModelState);

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

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

            currentPointOfInterest.Name        = newPointOfInterest.Name;
            currentPointOfInterest.Description = newPointOfInterest.Description;

            return(CreatedAtRoute("GetPointOfInterest",
                                  new { cityId = cityId, POIId = currentPointOfInterest.Id },
                                  newPointOfInterest));
        }
        public IActionResult PartialyUpdatePointOfInterest(int cityId, int id,
                                                           [FromBody] JsonPatchDocument <PointsOfInterestForUpdateDto> patchDoc)
        {
            if (patchDoc == null)
            {
                return(BadRequest());
            }

            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            var pointOfInterestFromStore = city.PointsOfInterest.FirstOrDefault(p => p.Id == id);

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

            var pointOfInterestToPatch =
                new PointsOfInterestForUpdateDto()
            {
                Name        = pointOfInterestFromStore.Name,
                Description = pointOfInterestFromStore.Description
            };

            patchDoc.ApplyTo(pointOfInterestToPatch, ModelState);

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

            if (pointOfInterestFromStore.Description == pointOfInterestFromStore.Name)
            {
                ModelState.AddModelError("Description", "The provided description shouldn't match the provided name");
            }

            TryValidateModel(pointOfInterestToPatch);

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

            pointOfInterestFromStore.Name        = pointOfInterestToPatch.Name;
            pointOfInterestFromStore.Description = pointOfInterestToPatch.Description;

            return(NoContent());
        }
예제 #7
0
        public IActionResult ReplacePointOfInterest(int poiId, int cityId, [FromBody] PointsOfInterestForUpdateDto poiUpdate)
        {
            if (!infoRepository.PoiExists(cityId, poiId))
            {
                return(NotFound());
            }

            var poiFromStore = cityInfoContext.PointOfInterests
                               .Where(c => c.CityId == cityId && c.Id == poiId)
                               .FirstOrDefault();

            var update = mapper.Map(poiUpdate, poiFromStore);

            infoRepository.UpdatePoi(cityId, poiFromStore);

            infoRepository.SaveChanges();

            return(NoContent());
        }
        public IActionResult partiallyUpdatePointOfInterest(int cityId, int id, [FromBody] JsonPatchDocument <PointsOfInterestForUpdateDto> patchDoc)
        {
            if (patchDoc == null)
            {
                return(BadRequest());
            }
            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

            if (city == null)
            {
                return(NotFound());
            }
            var interestPointFromStore = city.PointOfInterest.FirstOrDefault(interest => interest.Id == id);

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

            var interestPointToPatch = new PointsOfInterestForUpdateDto {
                Name        = interestPointFromStore.Name,
                Description = interestPointFromStore.Description
            };

            patchDoc.ApplyTo(interestPointToPatch, ModelState);

            if (interestPointToPatch.Description == interestPointToPatch.Name)
            {
                ModelState.AddModelError("Description", "Name and description cannot be the same");
            }
            TryValidateModel(interestPointToPatch);

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

            interestPointFromStore.Name        = interestPointToPatch.Name;
            interestPointFromStore.Description = interestPointToPatch.Description;

            return(NoContent());
        }
        public IActionResult UpdatePointOfInterest(int cityId, int id,
                                                   [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

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

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            var pointOfInterestEntity = _cityInfoRepository.GetPointOfInterestForCity(cityId, id);

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

            Mapper.Map(pointOfInterest, pointOfInterestEntity);

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }
        public IActionResult UpdatePointOfInterest(int cityId, int id,
                                                   [FromBody] PointsOfInterestForUpdateDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided description shouldn't match the provided name");
            }

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


            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

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

            var pointOfInterestFromStore = city.PointsOfInterest.FirstOrDefault(p => p.Id == id);

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

            pointOfInterestFromStore.Name        = pointOfInterest.Name;
            pointOfInterestFromStore.Description = pointOfInterest.Description;

            return(NoContent());
        }