public IActionResult UpdatePoint(int cityId, int id, [FromBody] PointOfInterestUpdateDTO pointOfInterestUpdateDTO) { if (pointOfInterestUpdateDTO == null) { return(BadRequest()); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId); var point = city.PointOfInterest.FirstOrDefault(p => p.Id == id); if (city == null || point == null) { return(NotFound()); } if (pointOfInterestUpdateDTO.Name == pointOfInterestUpdateDTO.Description) { ModelState.AddModelError("Description", "Description musr be differ"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } point.Name = pointOfInterestUpdateDTO.Name; point.Description = pointOfInterestUpdateDTO.Description; return(NoContent()); }
public IActionResult PartiallyUpdatePoint(int cityId, int id, [FromBody] JsonPatchDocument <PointOfInterestUpdateDTO> patchDoc) { if (patchDoc == null) { return(BadRequest()); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId); var point = city.PointOfInterest.FirstOrDefault(p => p.Id == id); if (city == null || point == null) { return(NotFound()); } var poinOfIntToPatch = new PointOfInterestUpdateDTO() { Name = point.Name, Description = point.Description }; patchDoc.ApplyTo(poinOfIntToPatch); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (poinOfIntToPatch.Name == poinOfIntToPatch.Description) { ModelState.AddModelError("Description", "Description musr be differ"); } TryValidateModel(point); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } point.Name = poinOfIntToPatch.Name; point.Description = poinOfIntToPatch.Description; return(NoContent()); }