public void Should_raise_bad_request_exception_on_invalid_hearing_role() { var request = new ParticipantRequest { CaseRoleName = "Applicant", HearingRoleName = "Missing hearing role" }; When(() => ParticipantRequestToNewParticipantMapper.Map(request, _caseType)) .Should().Throw <BadRequestException>().WithMessage("Invalid hearing role [Missing hearing role]"); }
public void Should_map_and_return_newparticipant_with_organistaion() { var request = new ParticipantRequest { Title = "Mr", FirstName = "Test", LastName = "Tester", Username = "******", CaseRoleName = "Respondent", HearingRoleName = "Representative", OrganisationName = "Test Corp Ltd" }; var newParticipant = ParticipantRequestToNewParticipantMapper.Map(request, _caseType); newParticipant.Should().NotBeNull(); var person = newParticipant.Person; person.Should().NotBeNull(); person.Organisation.Should().NotBeNull(); }
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()); }
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()); }