/// <summary> /// Creates a person /// </summary> /// <param name="newPerson">The person to create</param> /// <param name="countriesOfCitizenship">The countries of citizenship</param> /// <returns>The person created</returns> private Person CreatePerson(NewPerson newPerson, List <Location> countriesOfCitizenship) { var person = new Person { FirstName = (newPerson.IsSingleName) ? null : newPerson.FirstName, LastName = newPerson.LastName, GenderId = newPerson.Gender, DateOfBirth = newPerson.DateOfBirth, PlaceOfBirthId = newPerson.CityOfBirth, CountriesOfCitizenship = countriesOfCitizenship, IsDateOfBirthEstimated = newPerson.IsDateOfBirthEstimated, IsDateOfBirthUnknown = newPerson.IsDateOfBirthUnknown, IsPlaceOfBirthUnknown = newPerson.IsPlaceOfBirthUnknown, IsSingleName = newPerson.IsSingleName }; newPerson.Audit.SetHistory(person); this.Context.People.Add(person); this.logger.Trace("Creating new person {0}.", newPerson); return(person); }
/// <summary> /// Create a person /// </summary> /// <param name="newPerson">The person to create</param> /// <returns>The person created</returns> public async Task <Person> CreateAsync(NewPerson newPerson) { var project = await GetProjectByIdAsync(newPerson.ProjectId); var countriesOfCitizenship = await GetLocationsByIdAsync(newPerson.CountriesOfCitizenship); var person = CreatePerson(newPerson, countriesOfCitizenship); var participant = CreateParticipant(person, newPerson.ParticipantTypeId, project); var defaultExchangeVisitorFunding = await GetDefaultExchangeVisitorFunding(project.ProjectId); CreateParticipantExchangeVisitor(participant, project, defaultExchangeVisitorFunding); this.validator.ValidateCreate(GetPersonServiceValidationEntity( person: person, dateOfBirth: newPerson.DateOfBirth, genderId: newPerson.Gender, countriesOfCitizenship: countriesOfCitizenship, placeOfBirthId: newPerson.CityOfBirth, isDateOfBirthUnknown: newPerson.IsDateOfBirthUnknown, isDateOfBirthEstimated: newPerson.IsDateOfBirthEstimated, isPlaceOfBirthUnknown: newPerson.IsPlaceOfBirthUnknown )); this.logger.Trace("Created participant {0}.", newPerson); return(person); }
/// <summary> /// Get existing person /// </summary> /// <param name="newPerson">The person to lookup</param> /// <returns>The person found</returns> public async Task <Person> GetExistingPersonAsync(NewPerson newPerson) { this.logger.Trace("Retrieving person {0}.", newPerson); return(await CreateGetPerson(newPerson.FirstName, newPerson.LastName, newPerson.Gender, newPerson.DateOfBirth, newPerson.CityOfBirth).FirstOrDefaultAsync()); }