public BookingsHearingResponse MapHearingResponse(VideoHearing videoHearing) { var @case = videoHearing.GetCases().FirstOrDefault(); if (@case == null) { throw new ArgumentException("Hearing is missing case"); } if (videoHearing.CaseType == null) { throw new ArgumentException("Hearing is missing case type"); } if (videoHearing.HearingType == null) { throw new ArgumentException("Hearing is missing hearing type"); } var judgeParticipant = videoHearing.GetParticipants().FirstOrDefault(s => s.HearingRole?.UserRole != null && s.HearingRole.UserRole.Name == "Judge"); var judgeName = judgeParticipant != null ? judgeParticipant.DisplayName : string.Empty; var courtRoomAccount = judgeParticipant != null ? judgeParticipant.Person.Username : string.Empty; var response = new BookingsHearingResponse { HearingId = videoHearing.Id, HearingNumber = @case.Number, HearingName = @case.Name, ScheduledDuration = videoHearing.ScheduledDuration, ScheduledDateTime = videoHearing.ScheduledDateTime, HearingTypeName = videoHearing.HearingType.Name, CaseTypeName = videoHearing.CaseType.Name, CourtAddress = videoHearing.HearingVenueName, CourtRoom = videoHearing.HearingRoomName, CreatedDate = videoHearing.CreatedDate, CreatedBy = videoHearing.CreatedBy, LastEditDate = videoHearing.UpdatedDate, LastEditBy = videoHearing.UpdatedBy, ConfirmedBy = videoHearing.ConfirmedBy, ConfirmedDate = videoHearing.ConfirmedDate, JudgeName = judgeName, Status = videoHearing.Status.MapToContractEnum(), QuestionnaireNotRequired = videoHearing.QuestionnaireNotRequired, AudioRecordingRequired = videoHearing.AudioRecordingRequired, CancelReason = videoHearing.CancelReason, GroupId = videoHearing.SourceId, CourtRoomAccount = courtRoomAccount }; return(response); }