private async Task InviteOtherApplyingUsersToOrganisation(List <string> otherApplyingUsersEmails, string organisationId)
        {
            if (otherApplyingUsersEmails != null && !string.IsNullOrEmpty(organisationId))
            {
                // For any other user who was trying to apply for the same organisation; they now need to request access
                foreach (var email in otherApplyingUsersEmails)
                {
                    var otherApplyingContact = await _apiClient.GetEpaContactByEmail(email);

                    if (otherApplyingContact != null)
                    {
                        _logger.LogInformation($"Inviting contact ({otherApplyingContact.Email}) to {organisationId}");
                        var request = new AssociateEpaOrganisationWithEpaContactRequest
                        {
                            ContactId            = otherApplyingContact.Id,
                            OrganisationId       = organisationId,
                            ContactStatus        = ContactStatus.InvitePending,
                            MakePrimaryContact   = false,
                            AddDefaultRoles      = false,
                            AddDefaultPrivileges = false
                        };

                        await _apiClient.AssociateOrganisationWithEpaContact(request);
                    }
                }
            }
        }
 public async Task <bool> AssociateOrganisationWithEpaContact(AssociateEpaOrganisationWithEpaContactRequest associateEpaOrganisationWithEpaContactRequest)
 {
     using (var request = new HttpRequestMessage(HttpMethod.Put, $"api/ao/assessment-organisations/contacts/associate-organisation"))
     {
         return(await PostPutRequestWithResponse <AssociateEpaOrganisationWithEpaContactRequest, bool>(request,
                                                                                                       associateEpaOrganisationWithEpaContactRequest));
     }
 }
        private async Task AssignPrimaryContactToOrganisation(CreateEpaOrganisationContactRequest primaryContact, string organisationId)
        {
            if (primaryContact != null && !string.IsNullOrEmpty(organisationId))
            {
                var primaryContactId = Guid.Empty;

                var assessorContact = await _apiClient.GetEpaContactByEmail(primaryContact.Email);

                if (assessorContact is null)
                {
                    _logger.LogInformation($"Creating a new primary contact ({primaryContact.Email}) for {organisationId}");
                    var validationResponse = await _assessorValidationService.ValidateNewContactRequest(primaryContact);

                    if (!validationResponse.IsValid)
                    {
                        _logger.LogWarning($"Cannot create new primary contact in assessor for {organisationId}. Validation errors: {validationResponse.Errors.Select(err => err.ErrorMessage)}");
                    }
                    else
                    {
                        //Create a new contact in assessor table,
                        //Assumption is that this user will need to have an account created in aslogon too
                        //And then when they login the signinid etc wll get populated as it does for existing users
                        var id = await _apiClient.CreateEpaContact(primaryContact);

                        if (Guid.TryParse(id, out primaryContactId))
                        {
                            _logger.LogInformation($"Contact created successfully - {primaryContactId}");
                        }
                    }
                }
                else
                {
                    _logger.LogInformation($"Primary contact ({primaryContact.Email}) already exists");
                    primaryContactId = assessorContact.Id;
                }

                if (primaryContactId != Guid.Empty)
                {
                    _logger.LogInformation($"Associating primary contact ({primaryContact.Email}) to organisation {organisationId}");
                    var request = new AssociateEpaOrganisationWithEpaContactRequest
                    {
                        ContactId            = primaryContactId,
                        OrganisationId       = organisationId,
                        ContactStatus        = ContactStatus.Live,
                        MakePrimaryContact   = true,
                        AddDefaultRoles      = true,
                        AddDefaultPrivileges = false
                    };

                    await _apiClient.AssociateOrganisationWithEpaContact(request);
                }
            }
        }
Beispiel #4
0
        public async Task <IActionResult> AssociateEpaContactWithOrganisation([FromBody] AssociateEpaOrganisationWithEpaContactRequest request)
        {
            try
            {
                _logger.LogInformation($"Associating with Organisation [{request.OrganisationId}, {request.ContactId}]");
                var result = await _mediator.Send(request);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($@"Bad request, Message: [{ex.Message}]");
                return(BadRequest());
            }
        }
        private async Task AssignApplyingContactToOrganisation(string applyingUserEmail, string organisationId)
        {
            if (!string.IsNullOrEmpty(applyingUserEmail) && !string.IsNullOrEmpty(organisationId))
            {
                var applyingContact = await _apiClient.GetEpaContactByEmail(applyingUserEmail);

                if (applyingContact != null)
                {
                    _logger.LogInformation($"Associating applying contact ({applyingContact.Email}) to organisation {organisationId} with default privileges ");
                    var request = new AssociateEpaOrganisationWithEpaContactRequest
                    {
                        ContactId            = applyingContact.Id,
                        OrganisationId       = organisationId,
                        ContactStatus        = ContactStatus.Live,
                        MakePrimaryContact   = false,
                        AddDefaultRoles      = true,
                        AddDefaultPrivileges = true
                    };

                    await _apiClient.AssociateOrganisationWithEpaContact(request);
                }
            }
        }
 public async Task <bool> AssociateOrganisationWithEpaContact(AssociateEpaOrganisationWithEpaContactRequest request)
 {
     return(await Put <AssociateEpaOrganisationWithEpaContactRequest, bool>("api/ao/assessment-organisations/contacts/associate-organisation", request));
 }