public async Task <IActionResult> GetParticipantsByUsername(string username)
        {
            if (!username.IsValidEmail())
            {
                ModelState.AddModelError(nameof(username), $"Please provide a valid {nameof(username)}");
                return(BadRequest(ModelState));
            }

            var query        = new GetParticipantsByUsernameQuery(username);
            var participants = await _queryHandler.Handle <GetParticipantsByUsernameQuery, List <Participant> >(query);

            if (participants == null || participants.Count == 0)
            {
                return(NotFound());
            }

            var mapper = new ParticipantToResponseMapper();

            return(Ok(participants.Select(x => mapper.MapParticipantToResponse(x))));
        }
예제 #2
0
        public async Task <IActionResult> GetParticipantInHearing(Guid hearingId, Guid participantId)
        {
            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 query = new GetParticipantsInHearingQuery(hearingId);

            try
            {
                var participants = await _queryHandler.Handle <GetParticipantsInHearingQuery, List <Participant> >(query);

                var participant = participants.FirstOrDefault(x => x.Id == participantId);

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

                var mapper   = new ParticipantToResponseMapper();
                var response = mapper.MapParticipantToResponse(participant);

                return(Ok(response));
            }
            catch (HearingNotFoundException)
            {
                return(NotFound());
            }
        }
예제 #3
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 = new UpdateParticipantRequestValidation().Validate(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.IsIndividual)
            {
                var addressValidationResult = new AddressValidation().Validate(request);
                if (!addressValidationResult.IsValid)
                {
                    ModelState.AddFluentValidationErrors(result.Errors);
                    return(BadRequest(ModelState));
                }
            }

            if (participant.HearingRole.UserRole.IsRepresentative)
            {
                var repValidationResult = new RepresentativeValidation().Validate(request);
                if (!repValidationResult.IsValid)
                {
                    ModelState.AddFluentValidationErrors(result.Errors);
                    return(BadRequest(ModelState));
                }
            }

            var mapper  = new UpdateParticipantRequestToNewAddressMapper();
            var address = mapper.MapRequestToNewAddress(request);

            var representativeMapper = new UpdateParticipantRequestToNewRepresentativeMapper();
            var representative       = representativeMapper.MapRequestToNewRepresentativeInfo(request);

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

            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 == Domain.Enumerations.BookingStatus.Created)
            {
                await _eventPublisher.PublishAsync(new ParticipantUpdatedIntegrationEvent(hearingId, updatedParticipant));
            }

            return(Ok(response));
        }