public async Task <List <Participant> > AddParticipantToService(VideoHearing hearing, List <NewParticipant> participants)
        {
            var participantList = new List <Participant>();

            foreach (var participantToAdd in participants)
            {
                var existingPerson = await _context.Persons
                                     .Include("Organisation")
                                     .SingleOrDefaultAsync(x => x.Username == participantToAdd.Person.Username);

                switch (participantToAdd.HearingRole.UserRole.Name)
                {
                case "Individual":
                    var individual = hearing.AddIndividual(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                                           participantToAdd.CaseRole, participantToAdd.DisplayName);

                    UpdateOrganisationDetails(participantToAdd.Person, individual);
                    participantList.Add(individual);
                    break;

                case "Representative":
                {
                    var representative = hearing.AddRepresentative(existingPerson ?? participantToAdd.Person,
                                                                   participantToAdd.HearingRole,
                                                                   participantToAdd.CaseRole, participantToAdd.DisplayName,
                                                                   participantToAdd.Representee);

                    UpdateOrganisationDetails(participantToAdd.Person, representative);
                    participantList.Add(representative);
                    break;
                }

                case "Judicial Office Holder":
                {
                    var joh = hearing.AddJudicialOfficeHolder(existingPerson ?? participantToAdd.Person,
                                                              participantToAdd.HearingRole, participantToAdd.CaseRole, participantToAdd.DisplayName);

                    participantList.Add(joh);
                    break;
                }

                case "Judge":
                {
                    var judge = hearing.AddJudge(existingPerson ?? participantToAdd.Person,
                                                 participantToAdd.HearingRole,
                                                 participantToAdd.CaseRole, participantToAdd.DisplayName);

                    participantList.Add(judge);
                    break;
                }

                default:
                    throw new DomainRuleException(nameof(participantToAdd.HearingRole.UserRole.Name),
                                                  $"Role {participantToAdd.HearingRole.UserRole.Name} not recognised");
                }
            }

            return(participantList);
        }
예제 #2
0
        public async Task AddParticipantToService(VideoHearing hearing, List <NewParticipant> participants)
        {
            foreach (var participantToAdd in participants)
            {
                var existingPerson = await _context.Persons
                                     .Include("Address")
                                     .Include("Organisation")
                                     .SingleOrDefaultAsync(x => x.Username == participantToAdd.Person.Username);

                switch (participantToAdd.HearingRole.UserRole.Name)
                {
                case "Individual":
                    var individual = hearing.AddIndividual(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                                           participantToAdd.CaseRole, participantToAdd.DisplayName);

                    UpdateAddressAndOrganisationDetails(participantToAdd.Person, individual);
                    break;

                case "Representative":
                {
                    var representative = hearing.AddRepresentative(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                                                   participantToAdd.CaseRole, participantToAdd.DisplayName,
                                                                   participantToAdd.Reference, participantToAdd.Representee);
                    UpdateAddressAndOrganisationDetails(participantToAdd.Person, representative);
                    break;
                }

                case "Judge":
                    hearing.AddJudge(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                     participantToAdd.CaseRole, participantToAdd.DisplayName);
                    break;

                default:
                    throw new DomainRuleException(nameof(participantToAdd.HearingRole.UserRole.Name),
                                                  $"Role {participantToAdd.HearingRole.UserRole.Name} not recognised");
                }
            }
        }
예제 #3
0
        public VideoHearingBuilder()
        {
            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 = false;
            const bool audioRecordingRequired   = true;
            var        cancelReason             = "Online abandonment (incomplete registration)";

            _videoHearing = Builder <VideoHearing> .CreateNew().WithFactory(() =>
                                                                            new VideoHearing(caseType, hearingType, scheduledDateTime, duration, venue, hearingRoomName,
                                                                                             otherInformation, createdBy, questionnaireNotRequired, audioRecordingRequired, cancelReason))
                            .Build();

            var applicantCaseRole = new CaseRole(1, "Applicant")
            {
                Group = CaseRoleGroup.Applicant
            };
            var respondentCaseRole = new CaseRole(2, "Respondent")
            {
                Group = CaseRoleGroup.Respondent
            };
            var applicantLipHearingRole = new HearingRole(1, "Litigant in person")
            {
                UserRole = new UserRole(1, "Individual")
            };
            var respondentRepresentativeHearingRole = new HearingRole(5, "Representative")
            {
                UserRole = new UserRole(1, "Representative")
            };

            var respondentLipHearingRole = new HearingRole(4, "Litigant in person")
            {
                UserRole = new UserRole(1, "Individual")
            };
            var judgeCaseRole = new CaseRole(5, "Judge")
            {
                Group = CaseRoleGroup.Judge
            };
            var judgeHearingRole = new HearingRole(13, "Judge")
            {
                UserRole = new UserRole(1, "Judge")
            };
            var johHearingRole = new HearingRole(14, "Judicial Office Holder")
            {
                UserRole = new UserRole(7, "Judicial Office Holder")
            };
            var johCaseRole = new CaseRole(11, "Winger")
            {
                Group = CaseRoleGroup.Winger
            };

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

            _judgePerson = new PersonBuilder(true).Build();
            _johPerson   = new PersonBuilder(true).Build();

            _videoHearing.AddIndividual(person1, applicantLipHearingRole, applicantCaseRole,
                                        $"{person1.FirstName} {person1.LastName}");
            var indApplicant = _videoHearing?.Participants.Last();

            indApplicant.SetProtected(nameof(indApplicant.CaseRole), applicantCaseRole);
            indApplicant.SetProtected(nameof(indApplicant.HearingRole), applicantLipHearingRole);

            _videoHearing.AddIndividual(person3, respondentLipHearingRole, respondentCaseRole,
                                        $"{person3.FirstName} {person3.LastName}");
            var indRespondent = _videoHearing?.Participants.Last();

            indRespondent.SetProtected(nameof(indApplicant.CaseRole), respondentCaseRole);
            indRespondent.SetProtected(nameof(indRespondent.HearingRole), respondentLipHearingRole);

            _videoHearing.AddRepresentative(person2, respondentRepresentativeHearingRole, respondentCaseRole,
                                            $"{person2.FirstName} {person2.LastName}", string.Empty);
            var repRespondent = _videoHearing?.Participants.Last();

            repRespondent.SetProtected(nameof(indApplicant.CaseRole), respondentCaseRole);
            repRespondent.SetProtected(nameof(repRespondent.HearingRole), respondentRepresentativeHearingRole);

            _videoHearing.AddJudge(_judgePerson, judgeHearingRole, judgeCaseRole,
                                   $"{_judgePerson.FirstName} {_judgePerson.LastName}");
            var judge = _videoHearing?.Participants.Last();

            judge.SetProtected(nameof(indApplicant.CaseRole), judgeCaseRole);
            judge.SetProtected(nameof(judge.HearingRole), judgeHearingRole);

            _videoHearing.AddJudicialOfficeHolder(_johPerson, johHearingRole, johCaseRole,
                                                  $"{_johPerson.FirstName} {_johPerson.LastName}");
            var joh = _videoHearing?.Participants.Last();

            joh.SetProtected(nameof(indApplicant.CaseRole), johCaseRole);
            joh.SetProtected(nameof(joh.HearingRole), johHearingRole);

            // 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);
        }
예제 #4
0
        public async Task <VideoHearing> SeedVideoHearing(Action <SeedVideoHearingOptions> configureOptions,
                                                          bool addSuitabilityAnswer = false, BookingStatus status = BookingStatus.Booked)
        {
            var options = new SeedVideoHearingOptions();

            configureOptions?.Invoke(options);
            var caseType = GetCaseTypeFromDb(options.CaseTypeName);

            var claimantCaseRole  = caseType.CaseRoles.First(x => x.Name == options.ClaimantRole);
            var defendantCaseRole = caseType.CaseRoles.First(x => x.Name == options.DefendentRole);
            var judgeCaseRole     = caseType.CaseRoles.First(x => x.Name == "Judge");

            var claimantLipHearingRole             = claimantCaseRole.HearingRoles.First(x => x.Name == options.ClaimantHearingRole);
            var claimantRepresentativeHearingRole  = claimantCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var defendantRepresentativeHearingRole = defendantCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var judgeHearingRole = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge");

            var hearingType = caseType.HearingTypes.First(x => x.Name == options.HearingTypeName);

            var venues = new RefDataBuilder().HearingVenues;

            var          person1                  = new PersonBuilder(true).WithOrganisation().WithAddress().Build();
            var          person2                  = new PersonBuilder(true).Build();
            var          person3                  = new PersonBuilder(true).Build();
            var          person4                  = new PersonBuilder(true).Build();
            var          scheduledDate            = DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
            const int    duration                 = 45;
            const string hearingRoomName          = "Room02";
            const string otherInformation         = "OtherInformation02";
            const string createdBy                = "*****@*****.**";
            const bool   questionnaireNotRequired = false;
            const bool   audioRecordingRequired   = true;
            var          cancelReason             = "Online abandonment (incomplete registration)";

            var videoHearing = new VideoHearing(caseType, hearingType, scheduledDate, duration,
                                                venues.First(), hearingRoomName, otherInformation, createdBy, questionnaireNotRequired,
                                                audioRecordingRequired, cancelReason);

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

            videoHearing.AddRepresentative(person2, claimantRepresentativeHearingRole, claimantCaseRole,
                                           $"{person2.FirstName} {person2.LastName}", string.Empty, "Ms X");

            videoHearing.AddRepresentative(person3, defendantRepresentativeHearingRole, defendantCaseRole,
                                           $"{person3.FirstName} {person3.LastName}", string.Empty, "Ms Y");

            videoHearing.AddJudge(person4, judgeHearingRole, judgeCaseRole, $"{person4.FirstName} {person4.LastName}");

            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", true);
            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", false);
            if (status == BookingStatus.Created)
            {
                videoHearing.UpdateStatus(BookingStatus.Created, createdBy, null);
            }

            await using (var db = new BookingsDbContext(_dbContextOptions))
            {
                await db.VideoHearings.AddAsync(videoHearing);

                await db.SaveChangesAsync();
            }

            var hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));

            _individualId = hearing.Participants.First(x =>
                                                       x.HearingRole.Name.ToLower().IndexOf("judge", StringComparison.Ordinal) < 0 &&
                                                       x.HearingRole.Name.ToLower().IndexOf("representative", StringComparison.Ordinal) < 0).Id;
            _participantRepresentativeIds = hearing.Participants
                                            .Where(x => x.HearingRole.Name.ToLower().IndexOf("representative", StringComparison.Ordinal) >= 0).Select(x => x.Id).ToList();

            if (addSuitabilityAnswer)
            {
                await AddQuestionnaire();
            }

            hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));
            _seededHearings.Add(hearing.Id);
            return(hearing);
        }
예제 #5
0
        public async Task <VideoHearing> SeedVideoHearing(Action <SeedVideoHearingOptions> configureOptions,
                                                          bool addSuitabilityAnswer = false, BookingStatus status = BookingStatus.Booked, int endPointsToAdd = 0, bool addJoh = false, bool withLinkedParticipants = false)
        {
            var options = new SeedVideoHearingOptions();

            configureOptions?.Invoke(options);
            var caseType = GetCaseTypeFromDb(options.CaseTypeName);

            var applicantCaseRole  = caseType.CaseRoles.First(x => x.Name == options.ApplicantRole);
            var respondentCaseRole = caseType.CaseRoles.First(x => x.Name == options.RespondentRole);
            var judgeCaseRole      = caseType.CaseRoles.First(x => x.Name == "Judge");

            var applicantLipHearingRole             = applicantCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var applicantRepresentativeHearingRole  = applicantCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var respondentRepresentativeHearingRole = respondentCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var respondentLipHearingRole            = respondentCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var judgeHearingRole = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge");

            var hearingType = caseType.HearingTypes.First(x => x.Name == options.HearingTypeName);

            var venues = new RefDataBuilder().HearingVenues;

            var          person1                  = new PersonBuilder(true).WithOrganisation().Build();
            var          person2                  = new PersonBuilder(true).Build();
            var          person3                  = new PersonBuilder(true).Build();
            var          person4                  = new PersonBuilder(true).Build();
            var          judgePerson              = new PersonBuilder(true).Build();
            var          johPerson                = new PersonBuilder(true).Build();
            var          scheduledDate            = options.ScheduledDate ?? DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
            const int    duration                 = 45;
            const string hearingRoomName          = "Room02";
            const string otherInformation         = "OtherInformation02";
            const string createdBy                = "*****@*****.**";
            const bool   questionnaireNotRequired = false;
            const bool   audioRecordingRequired   = true;
            var          cancelReason             = "Online abandonment (incomplete registration)";

            var videoHearing = new VideoHearing(caseType, hearingType, scheduledDate, duration,
                                                venues.First(), hearingRoomName, otherInformation, createdBy, questionnaireNotRequired,
                                                audioRecordingRequired, cancelReason);

            videoHearing.AddIndividual(person1, applicantLipHearingRole, applicantCaseRole,
                                       $"{person1.FirstName} {person1.LastName}");

            videoHearing.AddRepresentative(person2, applicantRepresentativeHearingRole, applicantCaseRole,
                                           $"{person2.FirstName} {person2.LastName}", "Ms X");

            videoHearing.AddRepresentative(person3, respondentRepresentativeHearingRole, respondentCaseRole,
                                           $"{person3.FirstName} {person3.LastName}", "Ms Y");

            videoHearing.AddIndividual(person4, respondentLipHearingRole, respondentCaseRole,
                                       $"{person4.FirstName} {person4.LastName}");

            videoHearing.AddJudge(judgePerson, judgeHearingRole, judgeCaseRole, $"{judgePerson.FirstName} {judgePerson.LastName}");

            if (addJoh)
            {
                var johCaseRole    = caseType.CaseRoles.First(x => x.Name == "Judicial Office Holder");
                var johHearingRole = johCaseRole.HearingRoles.First(x => x.Name == "Judicial Office Holder");
                videoHearing.AddJudicialOfficeHolder(johPerson, johHearingRole, johCaseRole,
                                                     $"{johPerson.FirstName} {johPerson.LastName}");
            }

            if (endPointsToAdd > 0)
            {
                var r = new RandomGenerator();
                for (int i = 0; i < endPointsToAdd; i++)
                {
                    var sip = r.GetWeakDeterministic(DateTime.UtcNow.Ticks, 1, 10);
                    var pin = r.GetWeakDeterministic(DateTime.UtcNow.Ticks, 1, 4);
                    videoHearing.AddEndpoints(new List <Endpoint>
                    {
                        new Endpoint($"new endpoint {i}", $"{sip}@hmcts.net", pin, null)
                    });
                }
            }

            if (withLinkedParticipants)
            {
                var interpretee = videoHearing.Participants[0];
                var interpreter = videoHearing.Participants[1];
                CreateParticipantLinks(interpretee, interpreter);
            }

            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", true);
            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", false);

            var dA = videoHearing.Participants[1];

            videoHearing.AddEndpoints(
                new List <Endpoint> {
                new Endpoint("new endpoint", Guid.NewGuid().ToString(), "pin", null),
                new Endpoint("new endpoint", Guid.NewGuid().ToString(), "pin", dA),
            });

            if (status == BookingStatus.Created)
            {
                videoHearing.UpdateStatus(BookingStatus.Created, createdBy, null);
            }

            await using (var db = new BookingsDbContext(_dbContextOptions))
            {
                await db.VideoHearings.AddAsync(videoHearing);

                await db.SaveChangesAsync();
            }

            var hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));

            _individualId = hearing.Participants.First(x => x.HearingRole.UserRole.IsIndividual).Id;
            _participantRepresentativeIds = hearing.Participants
                                            .Where(x => x.HearingRole.UserRole.IsRepresentative).Select(x => x.Id).ToList();

            if (addSuitabilityAnswer)
            {
                await AddQuestionnaire();
            }

            hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));
            _seededHearings.Add(hearing.Id);
            return(hearing);
        }
예제 #6
0
        public async Task <VideoHearing> SeedVideoHearingLinkedParticipants(Action <SeedVideoHearingOptions> configureOptions)
        {
            var options = new SeedVideoHearingOptions();

            configureOptions?.Invoke(options);
            var caseType = GetCaseTypeFromDb(options.CaseTypeName);

            var applicantCaseRole  = caseType.CaseRoles.First(x => x.Name == options.ApplicantRole);
            var respondentCaseRole = caseType.CaseRoles.First(x => x.Name == options.RespondentRole);
            var judgeCaseRole      = caseType.CaseRoles.First(x => x.Name == "Judge");

            var applicantLipHearingRole  = applicantCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var respondentLipHearingRole = respondentCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var judgeHearingRole         = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge");

            var hearingType = caseType.HearingTypes.First(x => x.Name == options.HearingTypeName);

            var venues = new RefDataBuilder().HearingVenues;

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

            var          scheduledDate            = DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
            const int    duration                 = 45;
            const string hearingRoomName          = "Room02";
            const string otherInformation         = "OtherInformation02";
            const string createdBy                = "*****@*****.**";
            const bool   questionnaireNotRequired = false;
            const bool   audioRecordingRequired   = true;
            var          cancelReason             = "Online abandonment (incomplete registration)";

            var videoHearing = new VideoHearing(caseType, hearingType, scheduledDate, duration,
                                                venues.First(), hearingRoomName, otherInformation, createdBy, questionnaireNotRequired,
                                                audioRecordingRequired, cancelReason);

            videoHearing.AddIndividual(person1, applicantLipHearingRole, applicantCaseRole,
                                       $"{person1.FirstName} {person1.LastName}");

            videoHearing.AddIndividual(person2, respondentLipHearingRole, respondentCaseRole,
                                       $"{person2.FirstName} {person2.LastName}");

            videoHearing.AddJudge(judgePerson, judgeHearingRole, judgeCaseRole, $"{judgePerson.FirstName} {judgePerson.LastName}");

            var interpretee = videoHearing.Participants[0];
            var interpreter = videoHearing.Participants[1];

            CreateParticipantLinks(interpretee, interpreter);

            await using (var db = new BookingsDbContext(_dbContextOptions))
            {
                await db.VideoHearings.AddAsync(videoHearing);

                await db.SaveChangesAsync();
            }

            var hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));

            _individualId = hearing.Participants.First(x => x.HearingRole.UserRole.IsIndividual).Id;
            _participantRepresentativeIds = hearing.Participants
                                            .Where(x => x.HearingRole.UserRole.IsRepresentative).Select(x => x.Id).ToList();

            hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));
            _seededHearings.Add(hearing.Id);
            return(hearing);
        }