public IActionResult Patch(int key, [FromBody] Delta <User> delta) { IEnumerable <string> invalidPropertyNames = delta.GetChangedPropertyNames().Except(new[] { "Email", "Profile" }); if (invalidPropertyNames.Any()) { foreach (string propertyName in invalidPropertyNames) { return(BadRequest(propertyName + " : This field is not allowed to be updated.")); } } var entity = _userRepository.GetByKey(key); if (entity == null) { return(NotFound()); } var map = new UsersMapper(); var model = map.FromEntity(entity); delta.Patch(model); var userEntity = map.ToEntity(model, entity); _userRepository.Update(userEntity); _userRepository.Save(); return(Ok()); }