public IActionResult UpdatePointOfInterest(int cityId, int id, [FromBody] PointOfinterestDtoUpdate pointOfInterest) { if (pointOfInterest.Description == pointOfInterest.Name) { ModelState.AddModelError( "Description", "The provided description should be different from the name."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(cities => cities.Id == cityId); if (city == null) { return(NotFound()); } var pointOfInterestFromStore = city.PointsOfInterest .FirstOrDefault(points => points.Id == id); if (pointOfInterest == null) { return(NotFound()); } pointOfInterestFromStore.Name = pointOfInterest.Name; pointOfInterestFromStore.Description = pointOfInterest.Description; return(NoContent()); }
public IActionResult PartiallyUpdateOfInterest(int cityId, int id, [FromBody] JsonPatchDocument <PointOfinterestDtoUpdate> patchDoc) { var city = CitiesDataStore.Current.Cities. FirstOrDefault(cities => cities.Id == cityId); if (city == null) { return(NotFound()); } var pointOfInterestFromStore = city.PointsOfInterest .FirstOrDefault(points => points.Id == id); if (pointOfInterestFromStore == null) { return(NotFound()); } var pointOfInterestPatch = new PointOfinterestDtoUpdate() { Name = pointOfInterestFromStore.Name, Description = pointOfInterestFromStore.Description }; patchDoc.ApplyTo(pointOfInterestPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (pointOfInterestPatch.Description == pointOfInterestPatch.Name) { ModelState.AddModelError( "Description", "Should be different from the name "); } if (!TryValidateModel(pointOfInterestPatch)) { return(BadRequest(ModelState)); } pointOfInterestFromStore.Name = pointOfInterestPatch.Name; pointOfInterestFromStore.Description = pointOfInterestPatch.Description; return(NoContent()); }