예제 #1
0
        //https://johnthiriet.com/efficient-api-calls/#
        static async Task <AIPUserResult> GetFromExternalServerAsync(string url)
        {
            AIPUserResult userResult = null;

            using (var client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    userResult = await response.Content.ReadAsAsync <AIPUserResult>();
                }
            }
            return(userResult);
        }
예제 #2
0
        //public IActionResult InviteCandidate(Guid candidateId, Guid invitedBy, string toTenant)
        public async Task <IActionResult> Invite([FromBody] InviteViewModel model) //InviteCandidate(CandidateDto model)
        {
            string roleName        = model.Role;
            bool   inviteEmailSent = false;

            //TODO: aipApiService.TryInviteToTenant(user, toTenant);
            //AIP will return "invitation tocken" (aipInviteResult) with details : UserStatus (registered,not registered, registered in other tenant)
            string AIPinviteUserToTenantUrl = string.Format(@"{0}/check_account?tenant={1}&user_email={2}&roleName={3}", AIPHostUrl, model.TenantName, model.ToEmail, model.Role);//AIPHostUrl + "/Account/InviteUser?user="******"LALA_Invitationtocken", ActivateAccountURL = string.Format(@"https://{0}/activate_account?client_id={1}&tenant={2}&token={3}", AIPHostUrl, candidateId, toTenant, inviteToken)};

                if (aipInviteResult != null)// && aipInviteResult.RedirectUrl)
                {
                    //var inviteToken = inviteTicket.RegistractionToken;// -it will came from AIP return link (generated by AIP Token Service)
                    //inviteTicket.aipInviteAcceptURL OR registrationContinueUrl = string.Format(@"https://{0}/activate_account?client_id={1}&tenant={2}&token={3}", AIPHostUrl, candidateId, toTenant, inviteToken);

                    switch (aipInviteResult.UserStatus)
                    {
                    case UserAIPStatus.UserRegisteredInTenant:
                        //TODO: THERE no need to register user in Tenant again. But only add to other ROLE
                        //SO, aipActivateAccountURL will have OTHER message like 'Please, join a Role '{RoleName}' in {TenantName}'

                        // inviteEmailSent = WorkflowMessageManager.SendCandidateUserInviteJoinRoleMessage(candidateId, invitedBy, toTenant, aipActivateAccountURL);    //var emailTmpl = MessageTemplateManager.FindEmailByName(<CandidateInvitationEmail>);
                        break;

                    case UserAIPStatus.UserRegisteredInOtherTenant:
                    case UserAIPStatus.UserNotRegisteredOnAIP:
                        //TODO: there will be message 'Please, join {Tenant} and {Role}'
                        // inviteEmailSent = WorkflowMessageManager.SendCandidateUserInviteMessage(candidateId, invitedBy, toTenant, inviteTicket.aipActivateAccountURL);    //var emailTmpl = MessageTemplateManager.FindEmailByName(<CandidateInvitationEmail>);
                        break;

                    default:
                        //TODO: not result
                        break;
                    }
                }

                if (inviteEmailSent)
                {
                    string activityMsg = string.Format("User {0} invited to join tenant {1} as {2}", model.ToEmail, _currentTenant?.Name, model.Role);
                    //_userActivityService.RecordActivity(Consultant.Consultant_Sent_CandidateInvite,
                    //                                    nameof(Candidate), candidateId.ToString(),
                    //                                    _currentUserName, _currentTenant?.Name,
                    //                                    activityMsg);
                    //_logger.LogInformation(UserActivityLogTypes.Consultant.Consultant_Sent_CandidateInvite);

                    //ScopedMediator.Publish<InvitationSent>(inviteSent);
                }
                return(Ok(inviteEmailSent));
            }
            catch (Exception ex)
            {
                //return InternalServerError(new ApplicationException("Error to send letter exception: " + ex.Message));
                //var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                //{
                //     Content = new HttpContent(ex.InnerException);
                //};
                //return response;

                return(BadRequest(ex.Message));
            }
        }