public ActionResult PartiallyUpdateView(int viewId, JsonPatchDocument <ViewForUpdateDto> patchDocument) { var viewFromRepo = _croudSeekRepository.GetView(viewId, true); if (viewFromRepo == null) { return(NotFound()); } var viewToPatch = _mapper.Map <ViewForUpdateDto>(viewFromRepo); // add validation patchDocument.ApplyTo(viewToPatch, ModelState); if (viewToPatch == null) { return(NotFound()); } if (viewToPatch.UserWeights != null && viewToPatch.UserWeights.Select((w) => w.UserId).Distinct().Count() != viewToPatch.UserWeights.Count ) { ModelState.AddModelError("UserWeights", "There can only be one UserWeight per User."); } if (!TryValidateModel(viewToPatch)) { return(ValidationProblem(ModelState)); } _mapper.Map(viewToPatch, viewFromRepo); _croudSeekRepository.UpdateView(viewFromRepo); _croudSeekRepository.Save(); return(NoContent()); }