public async Task AddParticipantLinks(Guid hearingId, EditHearingRequest request, HearingDetailsResponse hearing)
 {
     if (request.Participants.Any(x => x.LinkedParticipants != null && x.LinkedParticipants.Count > 0))
     {
         foreach (var requestParticipant in request.Participants.Where(x => x.LinkedParticipants.Any()))
         {
             if (requestParticipant.Id != null)
             {
                 continue;
             }
             var requests = new List <LinkedParticipantRequest>();
             foreach (var lp in requestParticipant.LinkedParticipants)
             {
                 requests.Add(new LinkedParticipantRequest
                 {
                     ParticipantContactEmail       = lp.ParticipantContactEmail,
                     LinkedParticipantContactEmail = lp.LinkedParticipantContactEmail
                 });
             }
             var updateParticipantRequest = new UpdateParticipantRequest
             {
                 LinkedParticipants = requests,
                 DisplayName        = requestParticipant.DisplayName,
                 OrganisationName   = requestParticipant.OrganisationName,
                 Representee        = requestParticipant.Representee,
                 TelephoneNumber    = requestParticipant.TelephoneNumber,
                 Title = requestParticipant.Title
             };
             var newParticipant = hearing.Participants.First(p => p.ContactEmail == requestParticipant.ContactEmail);
             await _bookingsApiClient.UpdateParticipantDetailsAsync(hearingId, newParticipant.Id, updateParticipantRequest);
         }
     }
 }
        public async Task ProcessExistingParticipants(Guid hearingId, HearingDetailsResponse hearing,
                                                      EditParticipantRequest participant)
        {
            var existingParticipant = hearing.Participants.FirstOrDefault(p => p.Id.Equals(participant.Id));

            if (existingParticipant != null)
            {
                if (existingParticipant.UserRoleName == "Individual" ||
                    existingParticipant.UserRoleName == "Representative")
                {
                    //Update participant
                    _logger.LogDebug("Updating existing participant {Participant} in hearing {Hearing}",
                                     existingParticipant.Id, hearingId);
                    var updateParticipantRequest = UpdateParticipantRequestMapper.MapTo(participant);
                    await _bookingsApiClient.UpdateParticipantDetailsAsync(hearingId, participant.Id.Value,
                                                                           updateParticipantRequest);
                }
                else if (existingParticipant.UserRoleName == "Judge")
                {
                    //Update Judge
                    _logger.LogDebug("Updating judge {Participant} in hearing {Hearing}",
                                     existingParticipant.Id, hearingId);
                    var updateParticipantRequest = new UpdateParticipantRequest
                    {
                        DisplayName = participant.DisplayName
                    };
                    await _bookingsApiClient.UpdateParticipantDetailsAsync(hearingId, participant.Id.Value,
                                                                           updateParticipantRequest);
                }
            }
        }
        private async Task UpdateLinksForExistingParticipant(EditHearingRequest request, HearingDetailsResponse hearing, EditParticipantRequest requestParticipant)
        {
            var participant = hearing.Participants.First(x => x.Id == requestParticipant.Id);
            var linkedParticipantsInRequest = request.Participants.First(x => x.Id == participant.Id)
                                              .LinkedParticipants.ToList();

            var requests =
                BuildLinkedParticipantRequestForExistingParticipant(hearing, participant, linkedParticipantsInRequest);

            var updateParticipantRequest = new UpdateParticipantRequest
            {
                LinkedParticipants = requests,
                DisplayName        = requestParticipant.DisplayName,
                OrganisationName   = requestParticipant.OrganisationName,
                Representee        = requestParticipant.Representee,
                TelephoneNumber    = requestParticipant.TelephoneNumber,
                Title = requestParticipant.Title
            };

            await _bookingsApiClient.UpdateParticipantDetailsAsync(hearing.Id, participant.Id,
                                                                   updateParticipantRequest);
        }
 public static BookingsApi.Contract.Requests.UpdateParticipantRequest WithLinkedParticipants(this BookingsApi.Contract.Requests.UpdateParticipantRequest updateParticipantRequest, string participantEmail, string interpreterEmail)
 {
     updateParticipantRequest.LinkedParticipants.Add(CreateLinkedParticipantRequest(participantEmail, interpreterEmail));
     updateParticipantRequest.LinkedParticipants.Add(CreateLinkedParticipantRequest(interpreterEmail, participantEmail));
     return(updateParticipantRequest);
 }