public async Task <InviteContactToOrganisationResponse> Handle(InviteContactToOrganisationRequest request, CancellationToken cancellationToken) { var existingContact = await _contactQueryRepository.GetContactFromEmailAddress(request.Email); if (existingContact != null) { return(new InviteContactToOrganisationResponse() { Success = false, ErrorMessage = existingContact.OrganisationId == request.OrganisationId ? "This email address is already registered against your organisation. You must use a unique email address." : "This email address is already registered against another organisation. You must use a unique email address." }); } var organisation = await _organisationQueryRepository.Get(request.OrganisationId); var newContact = await CreateNewContact(request, organisation); var inviter = await _contactQueryRepository.GetContactById(request.InvitedByContactId); await _signInService.InviteUserToOrganisation(request.Email, request.GivenName, request.FamilyName, newContact.Id, organisation.EndPointAssessorName, inviter.DisplayName); await _contactRepository.AddContactInvitation(request.InvitedByContactId, newContact.Id, organisation.Id); return(new InviteContactToOrganisationResponse { Success = true, ContactId = newContact.Id }); }