public IActionResult PartiallyUpdatePointOfInterest(int cityId, int id, [FromBody] JsonPatchDocument <PointOfInterestToUpdate> patchDoc) { if (patchDoc == null) { return(BadRequest()); } var city = CitiesDataStore.Current.Cities.SingleOrDefault(m => m.Id == cityId); if (city == null) { return(NotFound()); } var model = city.PointOfInterest.SingleOrDefault(m => m.Id == id); if (model == null) { return(BadRequest()); } var pointOfInterestToPatch = new PointOfInterestToUpdate() { Name = model.Name, Description = model.Name }; patchDoc.ApplyTo(pointOfInterestToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } model.Name = pointOfInterestToPatch.Name; model.Description = pointOfInterestToPatch.Description; return(NoContent()); }
public IActionResult UpdatePointOfInterest(int cityId, int Id, [FromBody] PointOfInterestToUpdate pointOfInterest) { if (pointOfInterest == null) { return(BadRequest()); } if (pointOfInterest.Description == pointOfInterest.Name) { ModelState.AddModelError("Desciption", "Name does not equal description"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CitiesDataStore.Current.Cities.SingleOrDefault(m => m.Id == cityId); if (city == null) { return(NotFound()); } var model = city.PointOfInterest.SingleOrDefault(m => m.Id == Id); if (model == null) { return(BadRequest()); } model.Name = pointOfInterest.Name; model.Description = pointOfInterest.Description; return(NoContent()); }