public IActionResult PutPerson([FromBody, Required] PersonSpecification specification) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var authority = IdentityRepository.GetAuthority(specification.Authority); if (authority == null) { ModelState.AddModelError( nameof(specification.Authority), $"Authority '{specification.Authority}' does not exist"); } ValidateIdentifierTypes(specification.Identifiers, nameof(specification.Identifiers)); ValidateSpecifications(specification.MatchSpecifications, nameof(specification.MatchSpecifications)); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } //identifierChecker.EnsureHasNoInvalidDuplicates(specification.Identifiers); var identifiers = IdentifierDtoMarshaller.ConvertToIdentifiers(specification.Identifiers); var person = FindMatchingPerson(specification.MatchSpecifications); if (person == null) { if (specification.UpdateMode == UpdateMode.UpdateOnly) { return(NotFound()); } person = IdentityRepository.CreatePerson(identifiers, authority); return(CreatedAtAction("GetPerson", new { id = person.Id }, new PersonCreatedResult { PersonId = person })); } if (specification.UpdateMode == UpdateMode.CreateOnly) { return(BadRequest(new { Message = $"Person already exists" })); } IdentityRepository.UpdatePerson(person, identifiers, authority); return(new SeeOtherOjectActionResult( "GetPerson", routeValues: new { id = person.Id }, result: new PersonCreatedResult { PersonId = person })); }