/// <summary> /// Update pii /// </summary> /// <param name="pii">The pii business model</param> /// <returns>The person updated</returns> public async Task <Person> UpdatePiiAsync(UpdatePii pii) { var existingPerson = await GetExistingPersonAsync(pii); if (existingPerson != null && pii.PersonId != existingPerson.PersonId) { this.logger.Trace("Found existing person {0}.", existingPerson); throw new EcaBusinessException("The person already exists."); } var personToUpdate = await GetPersonModelByIdAsync(pii.PersonId); var participant = await GetParticipantByPersonIdAsync(pii.PersonId); if (participant != null) { throwValidationErrorIfParticipantSevisInfoIsLocked(participant); } Location cityOfBirth = null; if (pii.CityOfBirthId.HasValue) { cityOfBirth = await GetLocationByIdAsync(pii.CityOfBirthId.Value); throwIfLocationNotFound(cityOfBirth, pii.CityOfBirthId.Value); } var countriesOfCitizenship = await GetLocationsByIdAsync(pii.CountriesOfCitizenship); DoUpdate(pii, personToUpdate, cityOfBirth, countriesOfCitizenship); return(personToUpdate); }
private void DoUpdate(UpdatePii updatePii, Person person, Location cityOfBirth, List <Location> countriesOfCitizenship) { validator.ValidateUpdate(GetPersonServiceValidationEntity( person: person, dateOfBirth: updatePii.DateOfBirth, genderId: updatePii.GenderId, countriesOfCitizenship: countriesOfCitizenship, placeOfBirthId: cityOfBirth != null ? cityOfBirth.LocationId : default(int?), isDateOfBirthUnknown: updatePii.IsDateOfBirthUnknown, isDateOfBirthEstimated: updatePii.IsDateOfBirthEstimated, isPlaceOfBirthUnknown: updatePii.IsPlaceOfBirthUnknown )); person.IsSingleName = updatePii.IsSingleName; person.FirstName = updatePii.FirstName; person.LastName = updatePii.LastName; person.NamePrefix = updatePii.NamePrefix; person.NameSuffix = updatePii.NameSuffix; person.GivenName = updatePii.GivenName; person.FamilyName = updatePii.FamilyName; person.MiddleName = updatePii.MiddleName; person.PassportName = updatePii.PassportName; person.Patronym = updatePii.Patronym; person.Alias = updatePii.Alias; person.GenderId = updatePii.GenderId; person.Ethnicity = updatePii.Ethnicity; person.PlaceOfBirth = cityOfBirth; person.PlaceOfBirthId = updatePii.CityOfBirthId; person.IsPlaceOfBirthUnknown = updatePii.IsPlaceOfBirthUnknown; person.DateOfBirth = updatePii.DateOfBirth; person.IsDateOfBirthUnknown = updatePii.IsDateOfBirthUnknown; person.MedicalConditions = updatePii.MedicalConditions; person.MaritalStatusId = updatePii.MaritalStatusId; person.IsDateOfBirthEstimated = updatePii.IsDateOfBirthEstimated; updatePii.Audit.SetHistory(person); SetCountriesOfCitizenship(countriesOfCitizenship, person); }
/// <summary> /// Get existing person /// </summary> /// <param name="pii">The pii to lookup</param> /// <returns>The person found</returns> public async Task <Person> GetExistingPersonAsync(UpdatePii pii) { this.logger.Trace("Retrieving person {0}.", pii); return(await CreateGetPerson(pii.FirstName, pii.LastName, pii.GenderId, pii.DateOfBirth, pii.CityOfBirthId).FirstOrDefaultAsync()); }