private async Task <List <BuilderParticipant> > AddFunctionalRoleParticipantsAsync( Invitation invitation, List <BuilderParticipant> meetingParticipants, List <ParticipantsForCommand> functionalRoleParticipants) { var codes = functionalRoleParticipants.Select(p => p.InvitedFunctionalRole.Code).ToList(); var functionalRoles = await _functionalRoleApiService.GetFunctionalRolesByCodeAsync(_plantProvider.Plant, codes); foreach (var participant in functionalRoleParticipants) { var fr = functionalRoles.SingleOrDefault(p => p.Code == participant.InvitedFunctionalRole.Code); if (fr != null) { invitation.AddParticipant(new Participant( _plantProvider.Plant, participant.Organization, IpoParticipantType.FunctionalRole, fr.Code, null, null, null, fr.Email, null, participant.SortKey)); if (fr.UsePersonalEmail != null && fr.UsePersonalEmail == false && fr.Email != null) { meetingParticipants.AddRange(InvitationHelper.SplitAndCreateOutlookParticipantsFromEmailList(fr.Email)); } if (fr.InformationEmail != null) { meetingParticipants.AddRange(InvitationHelper.SplitAndCreateOutlookParticipantsFromEmailList(fr.InformationEmail)); } foreach (var person in participant.InvitedFunctionalRole.InvitedPersons) { var frPerson = fr.Persons.SingleOrDefault(p => p.AzureOid == person.AzureOid.ToString()); if (frPerson != null) { invitation.AddParticipant(new Participant( _plantProvider.Plant, participant.Organization, IpoParticipantType.Person, fr.Code, frPerson.FirstName, frPerson.LastName, frPerson.UserName, frPerson.Email, new Guid(frPerson.AzureOid), participant.SortKey)); meetingParticipants = InvitationHelper.AddPersonToOutlookParticipantList(frPerson, meetingParticipants, person.Required); } } } else { throw new IpoValidationException( $"Could not find functional role with functional role code '{participant.InvitedFunctionalRole.Code}' on participant {participant.Organization}."); } } return(meetingParticipants); }