Пример #1
0
        public async Task <IActionResult> UpdateHearingDetails(Guid hearingId, [FromBody] UpdateHearingRequest request)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = new UpdateHearingRequestValidation().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());
            }

            var venue = await GetVenue(request.HearingVenueName);

            if (venue == null)
            {
                ModelState.AddModelError(nameof(request.HearingVenueName), "Hearing venue does not exist");
                return(BadRequest(ModelState));
            }

            var cases = MapCase(request.Cases);

            var command = new UpdateHearingCommand(hearingId, request.ScheduledDateTime,
                                                   request.ScheduledDuration, venue, request.HearingRoomName, request.OtherInformation,
                                                   request.UpdatedBy, cases, request.QuestionnaireNotRequired, request.AudioRecordingRequired);

            await _commandHandler.Handle(command);

            var hearingMapper = new HearingToDetailResponseMapper();
            var response      = hearingMapper.MapHearingToDetailedResponse(videoHearing);

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

            return(Ok(response));
        }
Пример #2
0
        public void Should_map_all_properties()
        {
            var refDataBuilder = new RefDataBuilder();
            var venue          = refDataBuilder.HearingVenues.First(x => x.Name == _hearingVenueName);
            var caseType       = new CaseType(1, _caseTypeName);
            var hearingType    = Builder <HearingType> .CreateNew().WithFactory(() => new HearingType(_hearingTypeName)).Build();

            var        scheduledDateTime        = DateTime.Today.AddDays(1).AddHours(11).AddMinutes(45);
            var        duration                 = 80;
            var        hearingRoomName          = "Roome03";
            var        otherInformation         = "OtherInformation03";
            var        createdBy                = "User03";
            const bool questionnaireNotRequired = true;
            const bool audioRecordingRequired   = true;
            var        cancelReason             = "Online abandonment (incomplete registration)";

            var hearing = new VideoHearing(caseType, hearingType, scheduledDateTime, duration, venue, hearingRoomName,
                                           otherInformation, createdBy, questionnaireNotRequired, audioRecordingRequired, cancelReason);

            _videoHearing = Builder <VideoHearing> .CreateNew().WithFactory(() =>
                                                                            hearing).Build();

            var claimantCaseRole       = new CaseRole(1, "Claimant");
            var claimantLipHearingRole = new HearingRole(1, "Claimant LIP")
            {
                UserRole = new UserRole(1, "Individual")
            };

            _videoHearing.AddCase("0875", "Test Case Add", false);

            var person1 = new PersonBuilder(true).Build();

            _videoHearing.AddIndividual(person1, claimantLipHearingRole, claimantCaseRole,
                                        $"{person1.FirstName} {person1.LastName}");

            var party = _videoHearing.GetParticipants().FirstOrDefault();

            party.SetProtected(nameof(party.CaseRole), claimantCaseRole);
            party.SetProtected(nameof(party.HearingRole), claimantLipHearingRole);

            // Set the navigation properties as well since these would've been set if we got the hearing from DB
            _videoHearing.SetProtected(nameof(_videoHearing.HearingType), hearingType);
            _videoHearing.SetProtected(nameof(_videoHearing.CaseType), caseType);
            _videoHearing.SetProtected(nameof(_videoHearing.HearingVenue), venue);

            var response = _mapper.MapHearingToDetailedResponse(_videoHearing);

            response.Should().BeEquivalentTo(response, options => options
                                             .Excluding(v => v.Id)
                                             );
        }
Пример #3
0
        public async Task <IActionResult> GetHearingDetailsById(Guid hearingId)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

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

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

            var hearingMapper = new HearingToDetailResponseMapper();
            var response      = hearingMapper.MapHearingToDetailedResponse(videoHearing);

            return(Ok(response));
        }
Пример #4
0
        public async Task <IActionResult> BookNewHearing(BookNewHearingRequest request)
        {
            var result = new BookNewHearingRequestValidation().Validate(request);

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

            var query    = new GetCaseTypeQuery(request.CaseTypeName);
            var caseType = await _queryHandler.Handle <GetCaseTypeQuery, CaseType>(query);


            if (caseType == null)
            {
                ModelState.AddModelError(nameof(request.CaseTypeName), "Case type does not exist");
                return(BadRequest(ModelState));
            }

            var individualRoles = caseType.CaseRoles.SelectMany(x => x.HearingRoles).Where(x => x.UserRole.IsIndividual).Select(x => x.Name).ToList();

            var addressValidationResult = AddressValidationHelper.ValidateAddress(individualRoles, request.Participants);

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

            var hearingType = caseType.HearingTypes.SingleOrDefault(x => x.Name == request.HearingTypeName);

            if (hearingType == null)
            {
                ModelState.AddModelError(nameof(request.HearingTypeName), "Hearing type does not exist");
                return(BadRequest(ModelState));
            }

            var venue = await GetVenue(request.HearingVenueName);

            if (venue == null)
            {
                ModelState.AddModelError(nameof(request.HearingVenueName), "Hearing venue does not exist");
                return(BadRequest(ModelState));
            }

            var mapper          = new ParticipantRequestToNewParticipantMapper();
            var newParticipants = request.Participants.Select(x => mapper.MapRequestToNewParticipant(x, caseType))
                                  .ToList();

            var cases = request.Cases.Select(x => new Case(x.Number, x.Name)).ToList();

            var createVideoHearingCommand = new CreateVideoHearingCommand(caseType, hearingType,
                                                                          request.ScheduledDateTime, request.ScheduledDuration, venue, newParticipants, cases,
                                                                          request.QuestionnaireNotRequired, request.AudioRecordingRequired)
            {
                HearingRoomName  = request.HearingRoomName,
                OtherInformation = request.OtherInformation,
                CreatedBy        = request.CreatedBy
            };

            await _commandHandler.Handle(createVideoHearingCommand);

            var videoHearingId = createVideoHearingCommand.NewHearingId;

            var getHearingByIdQuery = new GetHearingByIdQuery(videoHearingId);

            var queriedVideoHearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(getHearingByIdQuery);

            var hearingMapper = new HearingToDetailResponseMapper();
            var response      = hearingMapper.MapHearingToDetailedResponse(queriedVideoHearing);

            return(CreatedAtAction(nameof(GetHearingDetailsById), new { hearingId = response.Id }, response));
        }