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(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); _context.VideoHearings.Add(videoHearing); await _hearingService.AddParticipantToService(videoHearing, command.Participants); videoHearing.AddCases(command.Cases); await _context.SaveChangesAsync(); command.NewHearingId = videoHearing.Id; }
public async Task Handle(AddParticipantsToVideoHearingCommand command) { var hearing = await _context.VideoHearings .Include(x => x.Participants).ThenInclude(x => x.Person.Address) .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) .SingleOrDefaultAsync(x => x.Id == command.HearingId); if (hearing == null) { throw new HearingNotFoundException(command.HearingId); } _context.Update(hearing); await _hearingService.AddParticipantToService(hearing, command.Participants); 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; }