public async Task <bool> Handle(AssociateEpaOrganisationWithEpaContactRequest request, CancellationToken cancellationToken) { var success = false; var contact = await _registerQueryRepository.GetContactByContactId(request.ContactId); var organisation = await _registerQueryRepository.GetEpaOrganisationByOrganisationId(request.OrganisationId); if (contact != null && organisation != null) { await _registerRepository.AssociateOrganisationWithContact(contact.Id, organisation, request.ContactStatus, request.MakePrimaryContact? "MakePrimaryContact" : string.Empty); if (request.AddDefaultRoles) { await _registerRepository.AssociateDefaultRoleWithContact(contact); } if (request.AddDefaultPrivileges) { await _registerRepository.AssociateDefaultPrivilegesWithContact(contact); } success = true; } return(success); }
//Additional code to cater for ON-2047 private async Task CheckAndSetPrivileges(Contact existingContact) { if (existingContact.EndPointAssessorOrganisationId != null) { var orgHasContacts = await _organisationQueryRepository.CheckIfOrganisationHasContactsWithSigninId(existingContact .EndPointAssessorOrganisationId, existingContact.Id); if (!orgHasContacts) { await _registerRepository.AssociateDefaultPrivilegesWithContact(new EpaContact { Id = existingContact.Id }); } } }