MyDriving.ViewModel.LoginViewModel.LoginAsync C# (CSharp) Method

LoginAsync() private method

private LoginAsync ( MobileServiceAuthenticationProvider provider ) : Task
provider MobileServiceAuthenticationProvider
return Task
        async Task<bool> LoginAsync(MobileServiceAuthenticationProvider provider)
        {
            if (!Plugin.Connectivity.CrossConnectivity.Current.IsConnected)
            {
                Acr.UserDialogs.UserDialogs.Instance.Alert("Ensure you have internet connection to login.",
                    "No Connection", "OK");

                return false;
            }

            MobileServiceUser user = null;

            try
            {
                authentication.ClearCookies();
                user = await authentication.LoginAsync(client, provider);

                if (user != null)
                {
                    IsBusy = true;
                    UserProfile = await UserProfileHelper.GetUserProfileAsync(client);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Report(ex);
            }
            finally
            {
                IsBusy = false;
            }

            if (user == null || UserProfile == null)
            {
                Settings.LoginAccount = LoginAccount.None;
                Settings.UserFirstName = string.Empty;
                Settings.AuthToken = string.Empty;
                Settings.UserLastName = string.Empty;

                Logger.Instance.Track("LoginError");
                Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to login or create account.", "Login error", "OK");
                return false;
            }
            else
            {
                Init();

                Logger.Instance.Track("LoginSuccess");
            }

            return true;
        }
    }