public IActionResult PartiallyUpdatePointOfInterest(string cityId, string id, [FromBody] JsonPatchDocument <PointOfInterestUpdated> pathDoc) { if (pathDoc == null) { return(BadRequest()); } var city = CityDataStore.Current.Cities.FirstOrDefault(p => p.Id == new Guid(cityId)); if (city == null) { return(NotFound()); } var pointOfInterestFromStore = city.PointOfInterest.FirstOrDefault(p => p.Id == new Guid(id)); if (pointOfInterestFromStore == null) { return(NotFound()); } var pointOfInterestToPath = new PointOfInterestUpdated() { Name = pointOfInterestFromStore.Name, Description = pointOfInterestFromStore.Description }; pathDoc.ApplyTo(pointOfInterestToPath, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } pointOfInterestFromStore.Name = pointOfInterestToPath.Name; pointOfInterestFromStore.Description = pointOfInterestToPath.Description; return(Ok(pointOfInterestFromStore)); }
public IActionResult UpdatePointOfInterest(string cityId, string id, [FromBody] PointOfInterestUpdated pointOfInterest) { if (pointOfInterest == null) { return(BadRequest()); } if (pointOfInterest.Description == pointOfInterest.Name) { ModelState.AddModelError("Description", "The provided description should be different fron the name!"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CityDataStore.Current.Cities.FirstOrDefault(p => p.Id == new Guid(cityId)); if (city == null) { return(NotFound()); } var existPointOfInterest = city.PointOfInterest.FirstOrDefault(p => p.Id == new Guid(id)); if (existPointOfInterest == null) { return(NotFound()); } existPointOfInterest.Name = pointOfInterest.Name; existPointOfInterest.Description = pointOfInterest.Description; return(Ok(existPointOfInterest)); }