/// <summary> /// Creates a person dependent /// </summary> /// <param name="newPerson">The person to create</param> /// <param name="emails">The email addresses</param> /// <returns></returns> private async Task <PersonDependent> CreatePersonDependentAsync(NewPersonDependent newPerson, List <EmailAddress> emails) { var countriesOfCitizenship = GetCitizenshipCountriesById(0, newPerson.CountriesOfCitizenship); var dependent = new PersonDependent { PersonId = newPerson.PersonId, DependentTypeId = newPerson.DependentTypeId, FirstName = newPerson.FirstName, LastName = newPerson.LastName, NameSuffix = newPerson.NameSuffix, PassportName = newPerson.PassportName, PreferredName = newPerson.PreferredName, GenderId = newPerson.GenderId, DateOfBirth = newPerson.DateOfBirth, PlaceOfBirthId = newPerson.PlaceOfBirthId, PlaceOfResidenceId = newPerson.PlaceOfResidenceId, BirthCountryReasonId = newPerson.BirthCountryReasonId, EmailAddresses = emails, CountriesOfCitizenship = countriesOfCitizenship, IsTravellingWithParticipant = newPerson.IsTravellingWithParticipant }; newPerson.Audit.SetHistory(dependent); this.Context.PersonDependents.Add(dependent); this.logger.Trace("Creating new person dependent {0}.", newPerson); return(dependent); }
/// <summary> /// Create a person dependent /// </summary> /// <param name="newPersonDependent">The person dependent to create</param> /// <returns>The person create</returns> public async Task <PersonDependent> CreateDependentAsync(NewPersonDependent newDependent) { Contract.Requires(newDependent != null, "The dependent must not be null."); var emails = new List <EmailAddress>(); if (!string.IsNullOrEmpty(newDependent.EmailAddress)) { var email = new EmailAddress { EmailAddressTypeId = EmailAddressType.Personal.Id, IsPrimary = true, Address = newDependent.EmailAddress }; emails.Add(email); } var dependent = await CreatePersonDependentAsync(newDependent, emails); this.logger.Trace("Creating new person dependent {0}.", newDependent); return(dependent); }
/// <summary> /// Get existing dependent /// </summary> /// <param name="newDependent">The dependent to lookup</param> /// <returns>The dependent found</returns> public async Task <PersonDependent> GetExistingDependentAsync(NewPersonDependent newDependent) { this.logger.Trace("Retrieving dependent {0}.", newDependent); return(await CreateGetDependent(newDependent.FirstName, newDependent.LastName, newDependent.GenderId, newDependent.DateOfBirth, newDependent.PlaceOfBirthId).FirstOrDefaultAsync()); }