private static async Task <string> GetImpexiumUserRelations(IReadOnlyList <string> tokenList)
        {
            try
            {
                var appToken     = tokenList[0];
                var userToken    = tokenList[1];
                var baseUri      = tokenList[2];
                var userId       = tokenList[3];
                var findByUserId = "/Individuals/" + userId + "/Relationships/1?includeDetails=true";

                var headerDictionary = new Dictionary <string, string>
                {
                    { "AppToken", appToken },
                    { "UserToken", userToken }
                };

                var client = new RestClientNew(
                    baseUri + findByUserId,
                    HttpVerb.GET,
                    null,
                    headerDictionary);
                var json = await client.MakeRequest();

                return(json);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public async Task <List <UserAccess> > GetListOfUsers(string searchText)
        {
            List <UserAccess> usersList = new List <UserAccess>();

            try
            {
                var token = ReadfileAndReturnString();

                var    p           = token.Split('|');
                var    accessToken = p[0];
                var    apiEndPoint = p[1];
                string userEmail   = _impexiumProperties.ApiAccessEmail;
                string userPswd    = _impexiumProperties.ApiAccessPassword;

                var tokenList = await GetImpexiumUserToken(accessToken, apiEndPoint, userEmail, userPswd);

                if (tokenList.Count >= 4)
                {
                    var appToken         = tokenList[0];
                    var userToken        = tokenList[1];
                    var baseUri          = tokenList[2];
                    var userId           = tokenList[3];
                    var findOrgs         = "/Committees/ShowIssueTracker/Members/1?term=" + searchText;// " / Organizations/1?name=" + searchText;
                    var headerDictionary = new Dictionary <string, string> {
                        { "AppToken", appToken },
                        { "UserToken", userToken }
                    };
                    var client = new RestClientNew(
                        baseUri + findOrgs,
                        HttpVerb.GET,
                        null,
                        headerDictionary);
                    var json = await client.MakeRequest();

                    // Parse Result
                    var result = ParseJsonToDictionary(json);
                    if (result != null && result.Count > 0 && result.ContainsKey("dataList"))
                    {
                        dynamic       dResult  = JsonConvert.DeserializeObject(json);
                        List <object> dataList = GetList(result["dataList"]);
                        for (int i = 0; i < dataList.Count; i++)
                        {
                            var        dataListItem = dResult.dataList[i];
                            var        individual   = (dataListItem["emails"][0]);
                            UserAccess usssser      = new UserAccess()
                            {
                                Id = individual.address, Name = dataListItem.firstName + ' ' + dataListItem.lastName
                            };
                            usersList.Add(usssser);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(usersList);
        }
        private async Task <List <string> > GetImpexiumUserToken(string accessToken, string apiEndPoint, string userEmail, string userPassword)
        {
            try
            {
                var tokensList = new List <string>();
                // Step 2: Get AppToken or UserToken or Both
                // POST api/v1/Signup/Authenticate
                var headerDictionary = new Dictionary <string, string> {
                    { "AccessToken", accessToken }
                };

                var client = new RestClientNew(
                    apiEndPoint,
                    HttpVerb.POST,
                    "{\"AppId\":\"" + _impexiumProperties.AppId + "\",\"AppPassword\":\"" +
                    _impexiumProperties.AppKey
                    + "\",\"AppUserEmail\":\"" + userEmail + "\",\"AppUserPassword\":\"" + userPassword + "\"}",
                    headerDictionary);
                var json = await client.MakeRequest();



                switch (json)
                {
                case "ProtocolError":
                    tokensList.Add("ProtocolError");
                    return(tokensList);

                case "Unauthorized":
                    tokensList.Add("Unauthorized");
                    return(tokensList);

                case "Not Found":
                    tokensList.Add("Not Found");
                    return(tokensList);
                }


                dynamic result = JsonConvert.DeserializeObject(json);

                string appToken  = result.appToken;
                string userToken = result.userToken;
                string uri       = result.uri;
                string userId    = result.userId;

                tokensList.Add(appToken);
                tokensList.Add(userToken);
                tokensList.Add(uri);
                tokensList.Add(userId);

                return(tokensList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private async Task <string> GetImpexiumAccessToken()
        {
            try
            {
                // Step 1 : Get ApiEndPoint and AccessToken
                // POST api/v1/WebApiUrl

                var client = new RestClientNew(
                    _impexiumProperties.AccessEndPoint,
                    HttpVerb.POST,
                    "{\"AppName\":\"" + _impexiumProperties.AppId + "\",\"AppKey\":\"" +
                    _impexiumProperties.AppKey + "\"}");
                var json = await client.MakeRequest();

                switch (json)
                {
                case "ProtocolError":
                    return("ProtocolError");

                case "Unauthorized":
                    return("Unauthorized");

                case "Not Found":
                    return("Not Found");
                }

                dynamic result      = JsonConvert.DeserializeObject(json);
                string  apiEndPoint = result.uri;
                string  accessToken = result.accessToken;

                // add to local storage
                var local = accessToken + "|" + apiEndPoint +
                            "|" + DateTime.Now;
                WriteToFile(local);
                return(local);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public async Task SendEmailFromNADAAPI(string ccAddress, string toAddress, string subject, string body)
        {
            var emailapi = "*****@*****.**";
            var apipass  = "******";

            var client = new RestClientNew(
                "https://api.nada.org/api/account/token",
                HttpVerb.POST,
                "{\"Email\":\"" + emailapi + "\",\"Password\":\"" +
                apipass + "\"}");
            var json = await client.MakeRequest();

            dynamic tokenDetails = JsonConvert.DeserializeObject(json);

            var apiToken = tokenDetails.token;

            if (apiToken != "")
            {
                var emailTobeSent = "{\"ToEmail\":\"" + toAddress + "\",\"subject\":\"" + subject + "\",\"body\":\"" + body + "\",\"CCEmail\":\"" +
                                    ccAddress + "\"}";


                var headerDictionary = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + apiToken }
                };
                client = new RestClientNew(
                    "https://api.nada.org/api/nada/ComposeEmail",
                    HttpVerb.POST,
                    emailTobeSent,
                    headerDictionary);


                var jsonEmailSent = await client.MakeRequest();

                dynamic emailReponse = JsonConvert.DeserializeObject(jsonEmailSent);
            }
        }
        public async Task <string> findUserByEmailInImpexium(string email)
        {
            var token = ReadfileAndReturnString();

            var    p           = token.Split('|');
            var    accessToken = p[0];
            var    apiEndPoint = p[1];
            string userEmail   = _impexiumProperties.ApiAccessEmail;
            string userPswd    = _impexiumProperties.ApiAccessPassword;

            var tokenList = await GetImpexiumUserToken(accessToken, apiEndPoint, userEmail, userPswd);

            if (tokenList.Count >= 4)
            {
                var appToken         = tokenList[0];
                var userToken        = tokenList[1];
                var baseUri          = tokenList[2];
                var userId           = tokenList[3];
                var findOrgs         = "/Individuals/FindByEmail/" + email + "?includeDetails=true";
                var headerDictionary = new Dictionary <string, string> {
                    { "AppToken", appToken },
                    { "UserToken", userToken }
                };
                var client = new RestClientNew(
                    baseUri + findOrgs,
                    HttpVerb.GET,
                    null,
                    headerDictionary);
                var json = await client.MakeRequest();

                // Parse Result
                return(json);
            }
            else
            {
                return("");
            }
        }
        public async Task <string> GetImpexiumUserByEmail(string email)
        {
            try
            {
                var managerEmail = "";
                var token        = ReadfileAndReturnString();

                var    p           = token.Split('|');
                var    accessToken = p[0];
                var    apiEndPoint = p[1];
                string userEmail   = _impexiumProperties.ApiAccessEmail;
                string userPswd    = _impexiumProperties.ApiAccessPassword;

                var tokenList = await GetImpexiumUserToken(accessToken, apiEndPoint, userEmail, userPswd);

                if (tokenList.Count >= 4)
                {
                    var appToken         = tokenList[0];
                    var userToken        = tokenList[1];
                    var baseUri          = tokenList[2];
                    var userId           = tokenList[3];
                    var findOrgs         = "/Individuals/FindByEmail/" + email + "?includeDetails=true";
                    var headerDictionary = new Dictionary <string, string> {
                        { "AppToken", appToken },
                        { "UserToken", userToken }
                    };
                    var client = new RestClientNew(
                        baseUri + findOrgs,
                        HttpVerb.GET,
                        null,
                        headerDictionary);
                    var json = await client.MakeRequest();

                    // Parse Result
                    var result = ParseJsonToDictionary(json);


                    if (result != null && result.Count > 0 && result.ContainsKey("dataList"))
                    {
                        dynamic dResult = JsonConvert.DeserializeObject(json);
                        // List<object> dataList = GetList(result["dataList"]);

                        dynamic userdetails = JsonConvert.DeserializeObject(json);
                        var     dataList    = userdetails.dataList[0];
                        string  id          = dataList.id;
                        ///get User relationships
                        if (id != null)
                        {
                            //GET /api/v1/Individuals/{id}/Relationships/{pageNumber}
                            var indRelationship = "/Individuals/" + id + "/Relationships/1?includeDetails=true";
                            var clientRel       = new RestClientNew(
                                baseUri + indRelationship,
                                HttpVerb.GET,
                                null,
                                headerDictionary);

                            var jsonRelations = await clientRel.MakeRequest();

                            var resultRelations = ParseJsonToDictionary(jsonRelations);
                            if (resultRelations != null && resultRelations.Count > 0 && resultRelations.ContainsKey("dataList"))
                            {
                                /// Relationships
                                dynamic userReldetails = JsonConvert.DeserializeObject(jsonRelations);
                                var     indRelResult   = ParseJsonToDictionary(jsonRelations);
                                var     dataRelList    = GetList(indRelResult["dataList"]);
                                var     individualRel  = GetDictionary(dataRelList[0]);
                                for (var app = 0; app <= dataRelList.Count - 1; app++)
                                {
                                    individualRel = GetDictionary(dataRelList[app]);
                                    if (individualRel != null)
                                    {
                                        var relationName = individualRel["reciprocalRelationshipName"].ToString();
                                        switch (relationName.ToLower())
                                        {
                                        case "twenty group team leader":

                                            Dictionary <string, object> indRelatedCustomer = GetDictionary(
                                                individualRel["relatedToCustomer"]);
                                            if (indRelatedCustomer != null)
                                            {
                                                bool isManager = false;
                                                //  relationshipName
                                                foreach (var mem in indRelatedCustomer)
                                                {
                                                    if (mem.Key == "title")
                                                    {
                                                        var temp = mem.Value.ToString();
                                                        if (temp == "20 Group Consultant Manager")
                                                        {
                                                            isManager = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                                if (isManager)
                                                {
                                                    var userEmail2 = GetList(indRelatedCustomer["emails"]);
                                                    Dictionary <string, object> userEmailManager = GetDictionary(userEmail2[0]);
                                                    if (userEmailManager != null)
                                                    {
                                                        foreach (var mem in userEmailManager)
                                                        {
                                                            if (mem.Key == "address")
                                                            {
                                                                managerEmail = mem.Value.ToString();
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    /// manger is not null
                                                    if (managerEmail != "")
                                                    {
                                                        var userManger = await _userManager.FindByEmailAsync(managerEmail);

                                                        if (userManger == null)
                                                        {
                                                            var      fullName = indRelatedCustomer["name"].ToString();
                                                            string[] names    = fullName.Split(' ');
                                                            if (names.Length > 1)
                                                            {
                                                                await PostManager(managerEmail, names[0].ToString(), names[1].ToString());
                                                            }
                                                            else
                                                            {
                                                                await PostManager(managerEmail, fullName, fullName);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            //await _userManager.AddToRoleAsync(user, SeedData.RoleConstants.consultant);
                                            break;
                                        }

                                        //MEMBER_TYPE
                                    }
                                }

                                ///end
                            }
                        }
                    }
                }
                return(managerEmail);
            }
            catch (Exception ex)
            {
                return(null);

                throw ex;
            }
        }