public static ValidationResult ValidateRepresentativeInfo(List <ParticipantRequest> participantRequests)
        {
            ValidationResult validationResult = new ValidationResult();

            foreach (ParticipantRequest participantRequest in participantRequests)
            {
                validationResult = new RepresentativeValidation().Validate(participantRequest);
                if (!validationResult.IsValid)
                {
                    return(validationResult);
                }
            }
            return(validationResult);
        }
Example #2
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));
        }
 public void OneTimeSetUp()
 {
     _representativeValidator = new RepresentativeValidation();
 }