private void DoCreateOrUpdate(
            UpdatedParticipantPerson updatedPerson,
            Participant participant,
            ParticipantPerson participantPerson,
            ParticipantType participantType,
            ParticipantStatus participantStatus,
            Organization host,
            Organization home,
            Address hostAddress,
            Address homeAddress)
        {
            participantPersonValidator.ValidateUpdate(GetUpdatedPersonParticipantValidationEntity(participantType));
            updatedPerson.Audit.SetHistory(participant);
            updatedPerson.Audit.SetHistory(participantPerson);

            participantPerson.HomeInstitutionId        = updatedPerson.HomeInstitutionId;
            participantPerson.HomeInstitutionAddressId = updatedPerson.HomeInstitutionAddressId;

            participantPerson.HostInstitutionId        = updatedPerson.HostInstitutionId;
            participantPerson.HostInstitutionAddressId = updatedPerson.HostInstitutionAddressId;
            participant.ParticipantTypeId   = updatedPerson.ParticipantTypeId;
            participant.ParticipantStatusId = updatedPerson.ParticipantStatusId;
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="updatedPerson"></param>
 /// <returns></returns>
 public Task CreateOrUpdateAsync(UpdatedParticipantPerson updatedPerson)
 {
     Contract.Requires(updatedPerson != null, "The updated person must not be null.");
     return(Task.FromResult <object>(null));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="updatedPerson"></param>
 public void CreateOrUpdate(UpdatedParticipantPerson updatedPerson)
 {
     Contract.Requires(updatedPerson != null, "The updated person must not be null.");
 }
        /// <summary>
        /// Updates a participant person with given updated participant information.
        /// </summary>
        /// <param name="updatedPerson">The updated participant person.</param>
        /// <returns>The task.</returns>
        public async Task CreateOrUpdateAsync(UpdatedParticipantPerson updatedPerson)
        {
            var participant = await CreateGetParticipantByIdQuery(updatedPerson.ParticipantId).FirstOrDefaultAsync();

            throwIfModelDoesNotExist(updatedPerson.ParticipantId, participant, typeof(Participant));
            throwSecurityViolationIfParticipantDoesNotBelongToProject(updatedPerson.Audit.User.Id, updatedPerson.ProjectId, participant);
            throwValidationErrorIfParticipantSevisInfoIsLocked(participant);

            //should be loaded as part of the query
            var participantPerson = await Context.ParticipantPersons.FindAsync(updatedPerson.ParticipantId);

            if (participantPerson == null)
            {
                participantPerson = DoCreateParticipantPerson(participant, updatedPerson.Audit);
            }

            Organization      host              = null;
            Organization      home              = null;
            Organization      placement         = null;
            Address           hostAddress       = null;
            Address           homeAddress       = null;
            Address           placementAddress  = null;
            ParticipantStatus participantStatus = null;

            if (updatedPerson.HomeInstitutionId.HasValue)
            {
                home = await CreateGetInstitutionByIdQuery(updatedPerson.HomeInstitutionId.Value).FirstOrDefaultAsync();

                throwIfModelDoesNotExist(updatedPerson.HomeInstitutionId.Value, home, typeof(Organization));

                if (updatedPerson.HomeInstitutionAddressId.HasValue)
                {
                    homeAddress = await CreateGetAddressByIdQuery(updatedPerson.HomeInstitutionAddressId.Value, home.OrganizationId).FirstOrDefaultAsync();

                    throwIfModelDoesNotExist(updatedPerson.HomeInstitutionAddressId.Value, homeAddress, typeof(Address));
                }
            }
            if (updatedPerson.HostInstitutionId.HasValue)
            {
                host = await CreateGetInstitutionByIdQuery(updatedPerson.HostInstitutionId.Value).FirstOrDefaultAsync();

                throwIfModelDoesNotExist(updatedPerson.HostInstitutionId.Value, host, typeof(Organization));

                if (updatedPerson.HostInstitutionAddressId.HasValue)
                {
                    hostAddress = await CreateGetAddressByIdQuery(updatedPerson.HostInstitutionAddressId.Value, host.OrganizationId).FirstOrDefaultAsync();

                    throwIfModelDoesNotExist(updatedPerson.HostInstitutionAddressId.Value, hostAddress, typeof(Address));
                }
            }
            if (updatedPerson.PlacementOrganizationId.HasValue)
            {
                host = CreateGetInstitutionByIdQuery(updatedPerson.PlacementOrganizationId.Value).FirstOrDefault();
                throwIfModelDoesNotExist(updatedPerson.PlacementOrganizationId.Value, host, typeof(Organization));

                if (updatedPerson.PlacementOrganizationAddressId.HasValue)
                {
                    placementAddress = CreateGetAddressByIdQuery(updatedPerson.PlacementOrganizationAddressId.Value, host.OrganizationId).FirstOrDefault();
                    throwIfModelDoesNotExist(updatedPerson.PlacementOrganizationAddressId.Value, placementAddress, typeof(Address));
                }
            }

            ParticipantType participantType = await Context.ParticipantTypes.FindAsync(updatedPerson.ParticipantTypeId);

            throwIfModelDoesNotExist(updatedPerson.ParticipantTypeId, participantType, typeof(ParticipantType));

            if (updatedPerson.ParticipantStatusId.HasValue)
            {
                participantStatus = await Context.ParticipantStatuses.FindAsync(updatedPerson.ParticipantStatusId.Value);

                throwIfModelDoesNotExist(updatedPerson.ParticipantStatusId.Value, participantStatus, typeof(ParticipantStatus));
            }

            DoCreateOrUpdate(
                updatedPerson: updatedPerson,
                participant: participant,
                participantPerson: participantPerson,
                participantType: participantType,
                participantStatus: participantStatus,
                host: host,
                home: home,
                hostAddress: hostAddress,
                homeAddress: homeAddress
                );
        }