public async Task UpdateUser(string signInName, string displayName, string givenName, string surname, string extension_jdrfConsId)
        {
            string JSON = await this.SearcUserBySignInNames(signInName);

            GraphAccounts users = GraphAccounts.Parse(JSON);

            // If user exists
            if (users != null && users.value != null && users.value.Count == 1)
            {
                string user = await SendGraphRequest($"/users/{users.value[0].objectId}", null, null, HttpMethod.Get);

                GraphUserUpdateModel graphUserUpdateModel = new GraphUserUpdateModel(displayName, givenName, surname, extension_jdrfConsId);
                string json = graphUserUpdateModel.ToString();
                await SendGraphRequest($"/users/{users.value[0].objectId}", null, json, new HttpMethod("PATCH"));
            }
        }
        public async Task <GraphAccountModel> GetUser(string signInName)
        {
            GraphAccountModel graphAccountModel = null;
            string            JSON = await this.SearchUserBySignInNames(signInName);

            GraphAccounts users = GraphAccounts.Parse(JSON);

            // If user exists
            if (users != null && users.value != null && users.value.Count == 1)
            {
                string user = await SendGraphRequest($"/users/{users.value[0].objectId}", null, null, HttpMethod.Get);

                graphAccountModel = GraphAccountModel.Parse(user);
            }

            return(graphAccountModel);
        }
        /// <summary>
        /// Delete user anccounts from Azure AD by SignInName (email address)
        /// </summary>
        public async Task DeleteAADUserBySignInNames(string signInName)
        {
            // First step, get the user account ID
            string JSON = await this.SearchUserBySignInNames(signInName);

            GraphAccounts users = GraphAccounts.Parse(JSON);

            // If the user account Id return successfully, iterate through all accounts
            if (users != null && users.value != null && users.value.Count > 0)
            {
                foreach (var item in users.value)
                {
                    // Send delete request to Graph API
                    await SendGraphRequest("/users/" + item.objectId, null, null, HttpMethod.Delete);
                }
            }
        }
        /// <summary>
        /// Update consumer user account's password
        /// </summary>
        /// <returns></returns>
        public async Task UpdateUserPassword(string signInName, string password)
        {
            string JSON = await this.SearchUserBySignInNames(signInName);

            GraphAccounts users = GraphAccounts.Parse(JSON);

            // If user exists
            if (users != null && users.value != null && users.value.Count == 1)
            {
                // Generate JSON containing the password and password policy
                GraphUserSetPasswordModel graphPasswordModel = new GraphUserSetPasswordModel(password);
                string json = JsonConvert.SerializeObject(graphPasswordModel);

                // Send the request to Graph API
                await SendGraphRequest("/users/" + users.value[0].objectId, null, json, new HttpMethod("PATCH"));
            }
        }
        public async Task <GraphAccountModel> GetUserByUserPrincipalName(string userPrincipalName)
        {
            GraphAccountModel graphAccountModel = null;
            string            JSON = await SendGraphRequest("/users/",
                                                            $"$filter=userPrincipalName eq '{userPrincipalName}'",
                                                            null, HttpMethod.Get);

            GraphAccounts users = GraphAccounts.Parse(JSON);

            // If user exists
            if (users != null && users.value != null && users.value.Count == 1)
            {
                string user = await SendGraphRequest($"/users/{users.value[0].objectId}", null, null, HttpMethod.Get);

                graphAccountModel = GraphAccountModel.Parse(user);
            }

            return(graphAccountModel);
        }