public IActionResult UpdatePointsOfInterest(int cityid, int id, [FromBody] PointsOfInterestforUpdate pointofInterest) { if (pointofInterest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(x => x.ID == cityid); if (city == null) { return(NotFound()); } var pointOfInterestFromStore = city.PointsOfInterests.FirstOrDefault(x => x.Id == id); if (pointOfInterestFromStore == null) { return(NotFound()); } pointOfInterestFromStore.Name = pointofInterest.Name; pointOfInterestFromStore.Description = pointofInterest.Description; return(NoContent()); }
public IActionResult PatchPointsOfInterest(int cityId, int id, [FromBody] JsonPatchDocument <PointsOfInterestforUpdate> patchDoc) { if (patchDoc == null) { return(BadRequest()); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(x => x.ID == cityId); if (city == null) { return(NotFound()); } var pointOfInterestFromStore = city.PointsOfInterests.FirstOrDefault(x => x.Id == id); if (pointOfInterestFromStore == null) { return(NotFound()); } var pointOfInterestToPatch = new PointsOfInterestforUpdate() { Name = pointOfInterestFromStore.Name, Description = pointOfInterestFromStore.Description }; patchDoc.ApplyTo(pointOfInterestToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } pointOfInterestFromStore.Name = pointOfInterestToPatch.Name; pointOfInterestFromStore.Description = pointOfInterestToPatch.Description; return(NoContent()); }