コード例 #1
0
        public async Task <JsonResult> OrgUserDelete(int id, string id2)
        {
            T_PRT_ORG_USERS orgUser = _DbPortal.GetT_PRT_ORG_USERS_ByOrgUserID(id);
            int             succId  = _DbPortal.DeleteT_PRT_ORG_USERS(orgUser);

            if (succId > 0)
            {
                WordPressHelper.SetUserManager(_userManager);
                ApplicationUser appUser = await WordPressHelper.GetApplicationUser(orgUser.Id);

                WordPressHelper wordPressHelper = new WordPressHelper(_userManager, _DbPortal, _log, _emailSender);
                int             orgUserCount    = _DbPortal.GetOrgUsersCount(orgUser.Id);
                if (orgUserCount == 0)
                {
                    //if we have user in wordpress, make it inactive
                    if (appUser.WordPressUserId > 0)
                    {
                        //string wordPressUri = wordPressHelper.SetWordPressUri(orgUser.ORG_ID);
                        // string userName = wordPressHelper.GetUserName();
                        // string password = wordPressHelper.GetPassword();
                        int.TryParse(appUser.WordPressUserId.ToString(), out var wpuid);
                        //WordPressClient wordPressClient = await wordPressHelper.GetAuthenticatedWordPressClient(wordPressUri, userName, password);
                        WordPressClient wordPressClient = await wordPressHelper.GetAuthenticatedWordPressClient(orgUser.ORG_ID);

                        bool isUserUpdated = await wordPressHelper.UpdateWordPressUser(appUser, wordPressClient, wpuid, "inactive");
                    }
                }
                else
                {
                    //revoke access from the site/organization from wordpress
                    int.TryParse(appUser.WordPressUserId.ToString(), out var wpuid);
                    wordPressHelper.AddRemoveUserSite(wpuid, orgUser.ORG_ID, 0);
                }
                return(Json("Success"));
            }
            else
            {
                return(Json("Unable to delete user from organization."));
            }
        }