public async Task Handle(RemoveHearingCommand command)
        {
            var hearingsIncCloned = await _context.VideoHearings
                                    .Include(x => x.HearingCases).ThenInclude(x => x.Case)
                                    .Include(x => x.Participants).ThenInclude(x => x.Person).ThenInclude(x => x.Organisation)
                                    .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants).ThenInclude(x => x.Participant)
                                    .Include(x => x.Participants).ThenInclude(x => x.Questionnaire).ThenInclude(x => x.SuitabilityAnswers)
                                    .Include(x => x.Endpoints).ThenInclude(x => x.DefenceAdvocate)
                                    .Where(x => x.Id == command.HearingId || x.SourceId == command.HearingId).ToListAsync();

            if (hearingsIncCloned.IsNullOrEmpty())
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            _context.RemoveRange(hearingsIncCloned.SelectMany(h => h.GetEndpoints()));
            _context.RemoveRange(hearingsIncCloned.SelectMany(h => h.GetCases()));
            _context.RemoveRange(hearingsIncCloned.SelectMany(h => h.Participants.SelectMany(p => p.LinkedParticipants)));

            var persons       = GetPersonsToRemove(hearingsIncCloned);
            var organisations = persons.Where(p => p.Organisation != null).Select(x => x.Organisation).ToList();

            _context.RemoveRange(organisations);
            _context.RemoveRange(persons);

            _context.RemoveRange(hearingsIncCloned);

            await _context.SaveChangesAsync();
        }
        public async Task ClearUnattachedPersons(IEnumerable <string> removedPersons)
        {
            foreach (var personEmail in removedPersons)
            {
                await using var db = new BookingsDbContext(_dbContextOptions);
                var person = await db.Persons
                             .Include(x => x.Address)
                             .Include(x => x.Organisation)
                             .SingleOrDefaultAsync(x => x.ContactEmail == personEmail);

                if (person == null)
                {
                    return;
                }
                if (person.Address != null)
                {
                    db.Remove(person.Address);
                }
                if (person.Organisation != null)
                {
                    db.Remove(person.Organisation);
                }
                db.Remove(person);

                await db.SaveChangesAsync();
            }
        }
Esempio n. 3
0
        public async Task Handle(RemoveHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include("HearingCases.Case")
                          .Include("Participants.Person")
                          .Include("Participants.Person.Address")
                          .Include("Participants.Person.Organisation")
                          .Include("Participants.Questionnaire")
                          .Include("Participants.Questionnaire.SuitabilityAnswers")
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            _context.RemoveRange(hearing.GetCases());
            _context.Remove(hearing);

            var persons       = hearing.Participants.Select(x => x.Person).ToList();
            var organisations = persons.Where(p => p.Organisation != null).Select(x => x.Organisation).ToList();
            var addresses     = persons.Where(p => p.Address != null).Select(x => x.Address).ToList();

            _context.RemoveRange(organisations);
            _context.RemoveRange(addresses);
            _context.RemoveRange(persons);

            await _context.SaveChangesAsync();
        }
        public async Task Handle(AddJudiciaryPersonCommand command)
        {
            await _context.JudiciaryPersons.AddAsync(new JudiciaryPerson(command.ExternalRefId, command.PersonalCode,
                                                                         command.Title, command.KnownAs, command.Surname, command.Fullname, command.PostNominals, command.Email, command.HasLeft));

            await _context.SaveChangesAsync();
        }
Esempio n. 5
0
        public async Task Handle(UpdateEndPointOfHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(h => h.Participants).ThenInclude(x => x.Person)
                          .Include(h => h.Endpoints).ThenInclude(x => x.DefenceAdvocate)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            var endpoint = hearing.Endpoints.SingleOrDefault(e => e.Id == command.EndpointId);

            if (endpoint == null)
            {
                throw new EndPointNotFoundException(command.EndpointId);
            }

            if (!string.IsNullOrWhiteSpace(endpoint.DisplayName))
            {
                endpoint.UpdateDisplayName(command.DisplayName);
            }
            if (command.DefenceAdvocate != null)
            {
                var defenceAdvocate = hearing.GetParticipants().Single(x => x.Id == command.DefenceAdvocate.Id);
                endpoint.AssignDefenceAdvocate(defenceAdvocate);
            }
            else
            {
                endpoint.AssignDefenceAdvocate(null);
            }

            await _context.SaveChangesAsync();
        }
        public async Task <Booking> AddBooking(Booking entity)
        {
            bookingsDbContext.Bookings.Add(entity);
            int count = await bookingsDbContext.SaveChangesAsync();

            return(entity);
        }
        public async Task Handle(UpdateSuitabilityAnswersCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include("Participants.Person")
                          .Include("Participants.Questionnaire")
                          .Include("Participants.Questionnaire.SuitabilityAnswers")
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            var participant = hearing.Participants.FirstOrDefault(p => p.Id == command.ParticipantId);

            if (participant == null)
            {
                throw new ParticipantNotFoundException(command.ParticipantId);
            }

            if (participant.Questionnaire == null)
            {
                participant.Questionnaire = new Questionnaire
                {
                    Participant   = participant,
                    ParticipantId = participant.Id
                };
            }

            participant.Questionnaire.AddSuitabilityAnswers(command.SuitabilityAnswers);
            await _context.SaveChangesAsync();
        }
Esempio n. 8
0
        public async Task RemoveJudiciaryPersonAsync(JudiciaryPerson judiciaryPerson)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);

            db.JudiciaryPersons.Remove(judiciaryPerson);

            await db.SaveChangesAsync();
        }
        private async Task AddQuestionnaire()
        {
            await using var db = new BookingsDbContext(_dbContextOptions);
            AddIndividualQuestionnaire(db);
            AddRepresentativeQuestionnaire(db);

            await db.SaveChangesAsync();
        }
Esempio n. 10
0
        public async Task SeedVideoHearing(VideoHearing videoHearing)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);
            await db.VideoHearings.AddAsync(videoHearing);

            await db.SaveChangesAsync();

            _seededHearings.Add(videoHearing.Id);
        }
Esempio n. 11
0
        public async Task AddJudiciaryPerson(Guid?externalRefId = null)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);

            var judiciaryPerson = new JudiciaryPersonBuilder(externalRefId).Build();
            await db.JudiciaryPersons.AddAsync(judiciaryPerson);

            await db.SaveChangesAsync();

            AddJudiciaryPersonsForCleanup(judiciaryPerson.ExternalRefId);
        }
        public async Task Handle(UpdateHearingParticipantsCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(x => x.Participants).ThenInclude(x => x.Person.Organisation)
                          .Include(x => x.Participants).ThenInclude(x => x.HearingRole.UserRole)
                          .Include(x => x.Participants).ThenInclude(x => x.CaseRole)
                          .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants)
                          .Include(h => h.Endpoints).ThenInclude(x => x.DefenceAdvocate)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            _context.Update(hearing);

            foreach (var removedParticipantId in command.RemovedParticipantIds)
            {
                hearing.RemoveParticipantById(removedParticipantId, false);
            }

            await _hearingService.AddParticipantToService(hearing, command.NewParticipants);

            _hearingService.ValidateHostCount(hearing.Participants);

            var participants = hearing.GetParticipants().ToList();

            foreach (var newExistingParticipantDetails in command.ExistingParticipants)
            {
                var existingParticipant = participants.FirstOrDefault(x => x.Id == newExistingParticipantDetails.ParticipantId);

                if (existingParticipant == null)
                {
                    throw new ParticipantNotFoundException(newExistingParticipantDetails.ParticipantId);
                }

                existingParticipant.LinkedParticipants.Clear();

                existingParticipant.UpdateParticipantDetails(newExistingParticipantDetails.Title, newExistingParticipantDetails.DisplayName,
                                                             newExistingParticipantDetails.TelephoneNumber, newExistingParticipantDetails.OrganisationName);

                if (existingParticipant.HearingRole.UserRole.IsRepresentative)
                {
                    ((Representative)existingParticipant).UpdateRepresentativeDetails(
                        newExistingParticipantDetails.RepresentativeInformation.Representee);
                }
            }

            await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants);

            await _context.SaveChangesAsync();
        }
        public async Task Handle(UpdateHearingStatusCommand command)
        {
            var hearing = await _context.VideoHearings.SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            hearing.UpdateStatus(command.Status, command.UpdatedBy, command.CancelReason);
            await _context.SaveChangesAsync();
        }
Esempio n. 14
0
        public async Task Handle(UpdateJudiciaryPersonByExternalRefIdCommand command)
        {
            var person = await _context.JudiciaryPersons.SingleOrDefaultAsync(x => x.ExternalRefId == command.ExternalRefId);

            if (person == null)
            {
                throw new JudiciaryPersonNotFoundException(command.ExternalRefId);
            }

            person.Update(command.HasLeft);

            await _context.SaveChangesAsync();
        }
        public async Task Handle(UpdatePersonCommand command)
        {
            var person = await _context.Persons.FindAsync(command.PersonId);

            if (person == null)
            {
                throw new PersonNotFoundException(command.PersonId);
            }

            person.UpdatePerson(command.FirstName, command.LastName, command.Username);

            await _context.SaveChangesAsync();
        }
        public async Task Handle(UpdateJudiciaryPersonByExternalRefIdCommand command)
        {
            var person = await _context.JudiciaryPersons.SingleOrDefaultAsync(x => x.ExternalRefId == command.ExternalRefId);

            if (person == null)
            {
                throw new JudiciaryPersonNotFoundException(command.ExternalRefId);
            }

            person.Update(command.PersonalCode, command.Title, command.KnownAs, command.Surname, command.Fullname, command.PostNominals, command.Email, command.HasLeft);

            await _context.SaveChangesAsync();
        }
Esempio n. 17
0
        public async Task UpdateHearingCaseName(Guid hearingId, string caseName)
        {
            var hearing = await _context.VideoHearings.Include(x => x.HearingCases).ThenInclude(h => h.Case)
                          .FirstAsync(x => x.Id == hearingId);

            var existingCase = hearing.GetCases().First();

            hearing.UpdateCase(new Case(existingCase.Number, caseName)
            {
                IsLeadCase = existingCase.IsLeadCase
            });
            await _context.SaveChangesAsync();
        }
        public async Task Handle(AnonymisePersonCommand command)
        {
            var username = command.Username.ToLower().Trim();
            var person   = await _context.Persons.SingleOrDefaultAsync(x => x.Username.ToLower().Trim() == username);

            if (person == null)
            {
                throw new PersonNotFoundException(username);
            }

            person.AnonymisePerson();
            await _context.SaveChangesAsync();
        }
Esempio n. 19
0
        public async Task Handle(RemoveParticipantFromHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include("Participants.Person")
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            hearing.RemoveParticipant(command.Participant);
            await _context.SaveChangesAsync();
        }
Esempio n. 20
0
        public async Task Handle(AddCasesToHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include("HearingCases.Case")
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            hearing.AddCases(command.Cases);
            await _context.SaveChangesAsync();
        }
        public async Task <ActionResult <Review> > DeleteReview(long id)
        {
            var review = await _context.Reviews.FindAsync(id);

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

            _context.Reviews.Remove(review);
            await _context.SaveChangesAsync();

            return(review);
        }
Esempio n. 22
0
        public async Task Handle(RemoveParticipantFromHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(h => h.Participants).ThenInclude(x => x.Person)
                          .Include(h => h.Participants).ThenInclude(x => x.LinkedParticipants)
                          .Include(h => h.Endpoints).ThenInclude(x => x.DefenceAdvocate)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            hearing.RemoveParticipant(command.Participant);
            await _context.SaveChangesAsync();
        }
        public async Task Handle(UpdateHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include("HearingCases.Case")
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            hearing.UpdateHearingDetails(command.HearingVenue, command.ScheduledDateTime,
                                         command.ScheduledDuration, command.HearingRoomName, command.OtherInformation,
                                         command.UpdatedBy, command.Cases, command.QuestionnaireNotRequired, command.AudioRecordingRequired);

            await _context.SaveChangesAsync();
        }
Esempio n. 24
0
        public async Task Handle(CreateVideoHearingCommand command)
        {
            var videoHearing = new VideoHearing(command.CaseType, command.HearingType, command.ScheduledDateTime,
                                                command.ScheduledDuration, command.Venue, command.HearingRoomName,
                                                command.OtherInformation, command.CreatedBy, command.QuestionnaireNotRequired,
                                                command.AudioRecordingRequired, command.CancelReason);

            _context.VideoHearings.Add(videoHearing);

            await _hearingService.AddParticipantToService(videoHearing, command.Participants);

            videoHearing.AddCases(command.Cases);

            await _context.SaveChangesAsync();

            command.NewHearingId = videoHearing.Id;
        }
Esempio n. 25
0
        public async Task Handle(AddEndPointToHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(h => h.Participants).ThenInclude(x => x.Person)
                          .Include(h => h.Endpoints).ThenInclude(x => x.DefenceAdvocate)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            var dto             = command.Endpoint;
            var defenceAdvocate = DefenceAdvocateHelper.CheckAndReturnDefenceAdvocate(dto.DefenceAdvocateUsername, hearing.GetParticipants());
            var endpoint        = new Endpoint(dto.DisplayName, dto.Sip, dto.Pin, defenceAdvocate);

            hearing.AddEndpoint(endpoint);
            await _context.SaveChangesAsync();
        }
        public async Task Handle(AddParticipantsToVideoHearingCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(x => x.Participants).ThenInclude(x => x.Person.Address)
                          .Include(x => x.Participants).ThenInclude(x => x.Person.Organisation)
                          .Include(x => x.Participants).ThenInclude(x => x.HearingRole.UserRole)
                          .Include(x => x.Participants).ThenInclude(x => x.CaseRole)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            _context.Update(hearing);
            await _hearingService.AddParticipantToService(hearing, command.Participants);

            await _context.SaveChangesAsync();
        }
        public async Task Handle(UpdateParticipantCommand command)
        {
            var hearing = await _context.VideoHearings
                          .Include(x => x.Participants).ThenInclude(x => x.Person.Organisation)
                          .Include(x => x.Participants).ThenInclude(x => x.HearingRole.UserRole)
                          .Include(x => x.Participants).ThenInclude(x => x.CaseRole)
                          .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants)
                          .SingleOrDefaultAsync(x => x.Id == command.HearingId);

            if (hearing == null)
            {
                throw new HearingNotFoundException(command.HearingId);
            }

            var participants = hearing.GetParticipants().ToList();

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

            if (participant == null)
            {
                throw new ParticipantNotFoundException(command.ParticipantId);
            }

            if (command.LinkedParticipants.Any() && participant.LinkedParticipants.Any())
            {
                await _hearingService.RemoveParticipantLinks(participants, participant);
            }
            await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants);

            participant.UpdateParticipantDetails(command.Title, command.DisplayName, command.TelephoneNumber,
                                                 command.OrganisationName);

            if (participant.HearingRole.UserRole.IsRepresentative)
            {
                ((Representative)participant).UpdateRepresentativeDetails(
                    command.RepresentativeInformation.Representee);
            }

            await _context.SaveChangesAsync();

            command.UpdatedParticipant = participant;
        }
Esempio n. 28
0
        public async Task ClearJudiciaryPersonsAsync()
        {
            foreach (var externalRefId in JudiciaryPersons)
            {
                try
                {
                    await using var db = new BookingsDbContext(_dbContextOptions);
                    var jp = await db.JudiciaryPersons.SingleOrDefaultAsync(x => x.ExternalRefId == externalRefId);

                    db.JudiciaryPersons.Remove(jp);
                    await db.SaveChangesAsync();

                    TestContext.WriteLine(@$ "Remove Judiciary Person: {externalRefId}.");
                }
                catch (JudiciaryPersonNotFoundException)
                {
                    TestContext.WriteLine(@$ "Ignoring cleanup for Judiciary Person: {externalRefId}. Does not exist.");
                }
            }
        }
        private async Task <Person> SeedPerson(bool withOrganisation = false)
        {
            var builder = new PersonBuilder(true);

            if (withOrganisation)
            {
                builder.WithOrganisation();
            }

            var newPerson = builder.Build();

            using (var db = new BookingsDbContext(BookingsDbContextOptions))
            {
                await db.Persons.AddAsync(newPerson);

                await db.SaveChangesAsync();
            }

            return(newPerson);
        }
Esempio n. 30
0
        public async Task Handle(UpdateParticipantCommand command)
        {
            var participants = command.VideoHearing.GetParticipants().ToList();

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

            if (participant == null)
            {
                throw new ParticipantNotFoundException(command.ParticipantId);
            }

            participant.UpdateParticipantDetails(command.Title, command.DisplayName, command.TelephoneNumber, command.NewAddress.Street, command.NewAddress.HouseNumber, command.NewAddress.City, command.NewAddress.County, command.NewAddress.Postcode, command.OrganisationName);

            if (participant.HearingRole.UserRole.IsRepresentative)
            {
                ((Representative)participant).UpdateRepresentativeDetails(
                    command.RepresentativeInformation.Reference,
                    command.RepresentativeInformation.Representee);
            }
            await _context.SaveChangesAsync();

            command.UpdatedParticipant = participant;
        }