public async Task Handle(UpdateHearingParticipantsCommand command) { var hearing = await _context.VideoHearings .Include(x => x.Participants).ThenInclude(x => x.Person.Organisation) .Include(x => x.Participants).ThenInclude(x => x.HearingRole.UserRole) .Include(x => x.Participants).ThenInclude(x => x.CaseRole) .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants) .Include(h => h.Endpoints).ThenInclude(x => x.DefenceAdvocate) .SingleOrDefaultAsync(x => x.Id == command.HearingId); if (hearing == null) { throw new HearingNotFoundException(command.HearingId); } _context.Update(hearing); foreach (var removedParticipantId in command.RemovedParticipantIds) { hearing.RemoveParticipantById(removedParticipantId, false); } await _hearingService.AddParticipantToService(hearing, command.NewParticipants); _hearingService.ValidateHostCount(hearing.Participants); var participants = hearing.GetParticipants().ToList(); foreach (var newExistingParticipantDetails in command.ExistingParticipants) { var existingParticipant = participants.FirstOrDefault(x => x.Id == newExistingParticipantDetails.ParticipantId); if (existingParticipant == null) { throw new ParticipantNotFoundException(newExistingParticipantDetails.ParticipantId); } existingParticipant.LinkedParticipants.Clear(); existingParticipant.UpdateParticipantDetails(newExistingParticipantDetails.Title, newExistingParticipantDetails.DisplayName, newExistingParticipantDetails.TelephoneNumber, newExistingParticipantDetails.OrganisationName); if (existingParticipant.HearingRole.UserRole.IsRepresentative) { ((Representative)existingParticipant).UpdateRepresentativeDetails( newExistingParticipantDetails.RepresentativeInformation.Representee); } } await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants); await _context.SaveChangesAsync(); }
public async Task Handle(UpdateParticipantCommand command) { var hearing = await _context.VideoHearings .Include(x => x.Participants).ThenInclude(x => x.Person.Organisation) .Include(x => x.Participants).ThenInclude(x => x.HearingRole.UserRole) .Include(x => x.Participants).ThenInclude(x => x.CaseRole) .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants) .SingleOrDefaultAsync(x => x.Id == command.HearingId); if (hearing == null) { throw new HearingNotFoundException(command.HearingId); } var participants = hearing.GetParticipants().ToList(); var participant = participants.FirstOrDefault(x => x.Id == command.ParticipantId); if (participant == null) { throw new ParticipantNotFoundException(command.ParticipantId); } if (command.LinkedParticipants.Any() && participant.LinkedParticipants.Any()) { await _hearingService.RemoveParticipantLinks(participants, participant); } await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants); participant.UpdateParticipantDetails(command.Title, command.DisplayName, command.TelephoneNumber, command.OrganisationName); if (participant.HearingRole.UserRole.IsRepresentative) { ((Representative)participant).UpdateRepresentativeDetails( command.RepresentativeInformation.Representee); } await _context.SaveChangesAsync(); command.UpdatedParticipant = participant; }
public async Task Handle(AddParticipantsToVideoHearingCommand command) { var hearing = await _context.VideoHearings .Include(x => x.Participants).ThenInclude(x => x.Person.Organisation) .Include(x => x.Participants).ThenInclude(x => x.HearingRole.UserRole) .Include(x => x.Participants).ThenInclude(x => x.CaseRole) .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants) .SingleOrDefaultAsync(x => x.Id == command.HearingId); if (hearing == null) { throw new HearingNotFoundException(command.HearingId); } _context.Update(hearing); var participants = await _hearingService.AddParticipantToService(hearing, command.Participants); await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants); await _context.SaveChangesAsync(); }
public async Task Handle(CreateVideoHearingCommand command) { var videoHearing = new VideoHearing(command.CaseType, command.HearingType, command.ScheduledDateTime, command.ScheduledDuration, command.Venue, command.HearingRoomName, command.OtherInformation, command.CreatedBy, command.QuestionnaireNotRequired, command.AudioRecordingRequired, command.CancelReason); // denotes this hearing is cloned if (command.SourceId.HasValue) { videoHearing.SourceId = command.SourceId; } await _context.VideoHearings.AddAsync(videoHearing); var participants = await _hearingService.AddParticipantToService(videoHearing, command.Participants); await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants); videoHearing.AddCases(command.Cases); if (command.Endpoints != null && command.Endpoints.Count > 0) { var dtos = command.Endpoints; var newEndpoints = (from dto in dtos let defenceAdvocate = DefenceAdvocateHelper.CheckAndReturnDefenceAdvocate(dto.DefenceAdvocateUsername, videoHearing.GetParticipants()) select new Endpoint(dto.DisplayName, dto.Sip, dto.Pin, defenceAdvocate)).ToList(); videoHearing.AddEndpoints(newEndpoints); } await _context.SaveChangesAsync(); command.NewHearingId = videoHearing.Id; }