private async Task PopulateMSAccountData(MSAccountPageModel model, AccountDataContent content)
        {
            string              errorText = null;
            LiveConnectClient   client    = new LiveConnectClient(this.MSAuthClient.Session);
            LiveOperationResult meResult  = await QueryUserData(client, "me");

            if (meResult != null)
            {
                dynamic meInfo = meResult.Result;
                model.Name         = meInfo.name;
                model.ProfileImage = await GetProfileImageData(client);
            }
            else
            {
                errorText = "There was an error while retrieving the user's information. Please try again later.";
            }

            if (errorText == null &&
                (content & AccountDataContent.Contacts) == AccountDataContent.Contacts)
            {
                LiveOperationResult contactsResult = await QueryUserData(client, "me/contacts");

                if (contactsResult != null)
                {
                    dynamic contacts = contactsResult.Result;
                    model.Contacts = contacts.data;
                }
                else
                {
                    errorText = "There was an error while retrieving the user's contacts data. Please try again later.";
                }
            }

            model.Error = errorText;
        }
Beispiel #2
0
        private async Task <ActionResult> GetAccountDataView(AccountDataContent content)
        {
            string errorText   = null;
            string logoutUrl   = this.AuthClient.GetLogoutUrl(this.SiteRootPath + "account/logout");
            var    accountData = new AccountDataModel()
            {
                LogoutURL       = logoutUrl,
                ShowContactsURL = ShowContactsUrl,
                HomeURL         = this.SiteRootPath
            };

            LiveConnectClient   client   = new LiveConnectClient(this.AuthClient.Session);
            LiveOperationResult meResult = await QueryUserData(client, "me");

            if (meResult != null)
            {
                dynamic meInfo = meResult.Result;
                accountData.Name = meInfo.name;

                accountData.ProfileImage = await GetProfileImageData(client);
            }
            else
            {
                errorText = "There was an error while retrieving the user's information. Please try again later.";
            }

            if (errorText == null && (content & AccountDataContent.Contacts) == AccountDataContent.Contacts)
            {
                LiveOperationResult contactsResult = await QueryUserData(client, "me/contacts");

                if (contactsResult != null)
                {
                    dynamic contacts = contactsResult.Result;
                    accountData.Contacts = contacts.data;
                }
                else
                {
                    errorText = "There was an error while retrieving the user's contacts data. Please try again later.";
                }
            }

            accountData.Error = errorText;
            return(View("AccountData", accountData));
        }
        private async Task <ActionResult> BuildMSAccountPageView(string[] scopes, AccountDataContent content)
        {
            MSAccountStatus accountStatus = this.MSAccountStatus;

            MSAccountPageModel model = new MSAccountPageModel()
            {
                Status          = accountStatus,
                AjaxClientURL   = this.AjaxClientPath,
                ShowContactsURL = this.ShowContactsPath
            };

            if (accountStatus == MSAccountStatus.Connected)
            {
                await this.PopulateMSAccountData(model, content);
            }
            else
            {
                Dictionary <string, string> options = new Dictionary <string, string>();
                options["state"] = "connect";
                model.LoginUrl   = this.MSAuthClient.GetLoginUrl(scopes, this.SiteRootPath + "account/connectcallback", options);
            }

            return(View("MSAccountPage", model));
        }
        private async Task<ActionResult> BuildMSAccountPageView(string[] scopes, AccountDataContent content)
        {
            MSAccountStatus accountStatus = this.MSAccountStatus;

            MSAccountPageModel model = new MSAccountPageModel()
            {
                Status = accountStatus,
                AjaxClientURL = this.AjaxClientPath,
                ShowContactsURL = this.ShowContactsPath
            };

            if (accountStatus == MSAccountStatus.Connected)
            {
                await this.PopulateMSAccountData(model, content);
            }
            else
            {
                Dictionary<string, string> options = new Dictionary<string, string>();
                options["state"] = "connect";
                model.LoginUrl = this.MSAuthClient.GetLoginUrl(scopes, this.SiteRootPath + "account/connectcallback", options);
            }

            return View("MSAccountPage", model);
        }
        private async Task PopulateMSAccountData(MSAccountPageModel model, AccountDataContent content)
        {
            string errorText = null;
            LiveConnectClient client = new LiveConnectClient(this.MSAuthClient.Session);
            LiveOperationResult meResult = await QueryUserData(client, "me");
            if (meResult != null)
            {
                dynamic meInfo = meResult.Result;
                model.Name = meInfo.name;
                model.ProfileImage = await GetProfileImageData(client);
            }
            else
            {
                errorText = "There was an error while retrieving the user's information. Please try again later.";
            }

            if (errorText == null && 
                (content & AccountDataContent.Contacts) == AccountDataContent.Contacts)
            {
                LiveOperationResult contactsResult = await QueryUserData(client, "me/contacts");
                if (contactsResult != null)
                {
                    dynamic contacts = contactsResult.Result;
                    model.Contacts = contacts.data;
                }
                else
                {
                    errorText = "There was an error while retrieving the user's contacts data. Please try again later.";
                }
            }

            model.Error = errorText;
        }
        private async Task<ActionResult> GetAccountDataView(AccountDataContent content)
        {
            string errorText = null;
            string logoutUrl = this.AuthClient.GetLogoutUrl(this.SiteRootPath + "account/logout");
            var accountData = new AccountDataModel()
            {
                LogoutURL = logoutUrl,
                ShowContactsURL = ShowContactsUrl,
                HomeURL = this.SiteRootPath
            };

            LiveConnectClient client = new LiveConnectClient(this.AuthClient.Session);
            LiveOperationResult meResult = await QueryUserData(client, "me");
            if (meResult != null)
            {
                dynamic meInfo = meResult.Result;
                accountData.Name = meInfo.name;

                accountData.ProfileImage = await GetProfileImageData(client);
            }
            else
            {
                errorText = "There was an error while retrieving the user's information. Please try again later.";
            }

            if (errorText == null && (content & AccountDataContent.Contacts) == AccountDataContent.Contacts)
            {
                LiveOperationResult contactsResult = await QueryUserData(client, "me/contacts");
                if (contactsResult != null)
                {
                    dynamic contacts = contactsResult.Result;
                    accountData.Contacts = contacts.data;
                }
                else
                {
                    errorText = "There was an error while retrieving the user's contacts data. Please try again later.";
                }
            }

            accountData.Error = errorText;
            return View("AccountData", accountData);
        }