Example #1
0
        public void Should_Return_An_Empty_List_When_Request_Is_Null()
        {
            var dto = LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(null);

            dto.Should().NotBeNull();
            dto.Count.Should().Be(0);
        }
Example #2
0
        public void Should_Map_A_Single_LinkedParticipantRequest_To_Dto_Successfully()
        {
            var dto = LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(_requests);

            dto.Should().BeOfType <List <LinkedParticipantDto> >();
            dto.Count.Should().Be(1);
        }
Example #3
0
        public void Should_Map_Multiple_LinkedParticipantRequests_To_Dto_Successfully()
        {
            var secondRequest = new LinkedParticipantRequest
            {
                ParticipantContactEmail       = "*****@*****.**",
                LinkedParticipantContactEmail = "*****@*****.**",
                Type = LinkedParticipantType.Interpreter
            };

            _requests.Add(secondRequest);

            var dtos = LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(_requests);

            dtos.Count.Should().Be(2);
        }
Example #4
0
        public async Task <IActionResult> UpdateParticipantDetails(Guid hearingId, Guid participantId, [FromBody] UpdateParticipantRequest request)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            if (participantId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(participantId), $"Please provide a valid {nameof(participantId)}");
                return(BadRequest(ModelState));
            }

            var result = await new UpdateParticipantRequestValidation().ValidateAsync(request);

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

            var getHearingByIdQuery = new GetHearingByIdQuery(hearingId);
            var videoHearing        = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(getHearingByIdQuery);

            if (videoHearing == null)
            {
                return(NotFound());
            }
            Participant participant  = null;
            var         participants = videoHearing.GetParticipants();

            if (participants != null)
            {
                participant = participants.SingleOrDefault(x => x.Id.Equals(participantId));
            }

            if (participant == null)
            {
                return(NotFound());
            }

            if (participant.HearingRole.UserRole.IsRepresentative)
            {
                var test = new RepresentativeValidation();
                await test.ValidateAsync(request);

                var repValidationResult = await new RepresentativeValidation().ValidateAsync(request);
                if (!repValidationResult.IsValid)
                {
                    ModelState.AddFluentValidationErrors(result.Errors);
                    return(BadRequest(ModelState));
                }
            }

            var representative =
                UpdateParticipantRequestToNewRepresentativeMapper.MapRequestToNewRepresentativeInfo(request);

            var linkedParticipants =
                LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(request.LinkedParticipants);

            var updateParticipantCommand = new UpdateParticipantCommand(hearingId, participantId, request.Title,
                                                                        request.DisplayName, request.TelephoneNumber,
                                                                        request.OrganisationName, representative, linkedParticipants);

            await _commandHandler.Handle(updateParticipantCommand);

            var updatedParticipant = updateParticipantCommand.UpdatedParticipant;

            var participantMapper = new ParticipantToResponseMapper();

            ParticipantResponse response = null;

            if (updatedParticipant != null)
            {
                response = participantMapper.MapParticipantToResponse(updatedParticipant);
            }

            // ONLY publish this event when Hearing is set for ready for video
            if (videoHearing.Status == BookingStatus.Created)
            {
                await _eventPublisher.PublishAsync(new ParticipantUpdatedIntegrationEvent(hearingId, updatedParticipant));
            }

            return(Ok(response));
        }
Example #5
0
        public async Task <IActionResult> UpdateHearingParticipants(Guid hearingId,
                                                                    [FromBody] UpdateHearingParticipantsRequest request)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = new UpdateHearingParticipantsRequestValidation().Validate(request);

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

            var query        = new GetHearingByIdQuery(hearingId);
            var videoHearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(query);

            if (videoHearing == null)
            {
                return(NotFound());
            }

            var caseTypequery = new GetCaseTypeQuery(videoHearing.CaseType.Name);
            var caseType      = await _queryHandler.Handle <GetCaseTypeQuery, CaseType>(caseTypequery);

            var representativeRoles = caseType.CaseRoles.SelectMany(x => x.HearingRoles).Where(x => x.UserRole.IsRepresentative).Select(x => x.Name).ToList();
            var representatives     = request.NewParticipants.Where(x => representativeRoles.Contains(x.HearingRoleName)).ToList();

            var representativeValidationResult = RepresentativeValidationHelper.ValidateRepresentativeInfo(representatives);

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

            var newParticipants = request.NewParticipants
                                  .Select(x => ParticipantRequestToNewParticipantMapper.Map(x, videoHearing.CaseType)).ToList();

            var existingParticipants = request.ExistingParticipants
                                       .Select(x => new ExistingParticipantDetails
            {
                DisplayName               = x.DisplayName,
                OrganisationName          = x.OrganisationName,
                ParticipantId             = x.ParticipantId,
                RepresentativeInformation = new RepresentativeInformation {
                    Representee = x.Representee
                },
                TelephoneNumber = x.TelephoneNumber,
                Title           = x.Title
            }).ToList();

            var linkedParticipants =
                LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(request.LinkedParticipants);

            var command = new UpdateHearingParticipantsCommand(hearingId, existingParticipants, newParticipants, request.RemovedParticipantIds, linkedParticipants);

            try
            {
                await _commandHandler.Handle(command);
            }
            catch (DomainRuleException e)
            {
                ModelState.AddDomainRuleErrors(e.ValidationFailures);
                return(BadRequest(ModelState));
            }

            var hearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(query);

            // Publish this event if the hearing is ready for video
            if (hearing.Status == BookingStatus.Created)
            {
                await PublishUpdateHearingParticipantsEvent(hearing, existingParticipants, newParticipants, request.RemovedParticipantIds, linkedParticipants);
            }

            return(NoContent());
        }
Example #6
0
        public async Task <IActionResult> AddParticipantsToHearing(Guid hearingId,
                                                                   [FromBody] AddParticipantsToHearingRequest request)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = new AddParticipantsToHearingRequestValidation().Validate(request);

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

            var query        = new GetHearingByIdQuery(hearingId);
            var videoHearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(query);

            if (videoHearing == null)
            {
                return(NotFound());
            }

            var caseTypequery = new GetCaseTypeQuery(videoHearing.CaseType.Name);
            var caseType      = await _queryHandler.Handle <GetCaseTypeQuery, CaseType>(caseTypequery);

            var representativeRoles = caseType.CaseRoles.SelectMany(x => x.HearingRoles).Where(x => x.UserRole.IsRepresentative).Select(x => x.Name).ToList();
            var representatives     = request.Participants.Where(x => representativeRoles.Contains(x.HearingRoleName)).ToList();

            var representativeValidationResult = RepresentativeValidationHelper.ValidateRepresentativeInfo(representatives);

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

            var participants = request.Participants
                               .Select(x => ParticipantRequestToNewParticipantMapper.Map(x, videoHearing.CaseType)).ToList();
            var linkedParticipants =
                LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(request.LinkedParticipants);

            var command = new AddParticipantsToVideoHearingCommand(hearingId, participants, linkedParticipants);

            try
            {
                await _commandHandler.Handle(command);
            }
            catch (DomainRuleException e)
            {
                ModelState.AddDomainRuleErrors(e.ValidationFailures);
                return(BadRequest(ModelState));
            }

            var hearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(query);

            // ONLY publish this event when Hearing is set for ready for video
            if (hearing.Status == BookingStatus.Created)
            {
                await PublishParticipantsAddedEvent(participants, hearing);
            }

            return(NoContent());
        }