public async Task <IActionResult> UpdateEndpointAsync(Guid hearingId, Guid endpointId, UpdateEndpointRequest updateEndpointRequest)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = new UpdateEndpointRequestValidation().Validate(updateEndpointRequest);

            if (!result.IsValid)
            {
                ModelState.AddFluentValidationErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            try
            {
                var hearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(new GetHearingByIdQuery(hearingId));

                if (hearing == null)
                {
                    throw new HearingNotFoundException(hearingId);
                }
                var defenceAdvocate =
                    DefenceAdvocateHelper.CheckAndReturnDefenceAdvocate(updateEndpointRequest.DefenceAdvocateUsername,
                                                                        hearing.GetParticipants());
                var command = new UpdateEndPointOfHearingCommand(hearingId, endpointId, updateEndpointRequest.DisplayName, defenceAdvocate);
                await _commandHandler.Handle(command);

                var endpoint = hearing.GetEndpoints().SingleOrDefault(x => x.Id == endpointId);

                if (endpoint != null && hearing.Status == BookingStatus.Created)
                {
                    await _eventPublisher.PublishAsync(new EndpointUpdatedIntegrationEvent(hearingId, endpoint.Sip,
                                                                                           updateEndpointRequest.DisplayName, defenceAdvocate?.Person.Username));
                }
            }
            catch (HearingNotFoundException exception)
            {
                return(NotFound(exception.Message));
            }
            catch (EndPointNotFoundException exception)
            {
                return(NotFound(exception.Message));
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task Handle(AddEndPointToHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(h => h.Participants).ThenInclude(x => x.Person)
                          .Include(h => h.Endpoints).ThenInclude(x => x.DefenceAdvocate)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            var dto             = command.Endpoint;
            var defenceAdvocate = DefenceAdvocateHelper.CheckAndReturnDefenceAdvocate(dto.DefenceAdvocateUsername, hearing.GetParticipants());
            var endpoint        = new Endpoint(dto.DisplayName, dto.Sip, dto.Pin, defenceAdvocate);

            hearing.AddEndpoint(endpoint);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        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;
        }