Пример #1
0
        private async Task ExecuteLoginCommand()
        {
            bool isLoginSuccess = false;

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            loginCommand.ChangeCanExecute();

            try
            {
                isLoginSuccess = await itrade.GetAccessToken(this.UserName, this.Password);
            }
            catch (Exception ex)
            {
                isLoginSuccess = false;
            }

            finally
            {
                IsBusy = false;
                loginCommand.ChangeCanExecute();
            }

            if (isLoginSuccess)
            {
                if (Device.OS == TargetPlatform.Android)
                {
                    await Application.Current.MainPage.Navigation.PushModalAsync(new MainPage());
                }
                else
                {
                    await page.Navigation.PushModalAsync(new TradeMainPage());
                }
            }
            else
            {
                await page.DisplayAlert("Login Error", "Login Error! please try Again", "Ok");
            }
        }
Пример #2
0
        private async Task ExecuteRegisterCommand()
        {
            bool isRegisterSuccess = false;
            bool isLoginSuccess    = false;

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            registerCommand.ChangeCanExecute();

            try
            {
                isRegisterSuccess = await itrade.RegisterAsync(this.UserName, this.Password, this.Confirmpassword);
            }
            catch (Exception ex)
            {
                isRegisterSuccess = false;
            }

            finally
            {
                IsBusy = false;
                registerCommand.ChangeCanExecute();
            }

            if (isRegisterSuccess)
            {
                await page.DisplayAlert("Feedback", "You have successfully Joined Us", "Ok");

                IsBusy = true;
                try
                {
                    isLoginSuccess = await itrade.GetAccessToken(this.UserName, this.Password);
                }
                catch (Exception)
                {
                    isLoginSuccess = false;
                }
                finally
                {
                    IsBusy = false;
                    registerCommand.ChangeCanExecute();
                }
                if (isLoginSuccess)
                {
                    Settings.AuthUserName = this.username;
                    await page.Navigation.PushAsync(new TradeMainPage());
                }
                else
                {
                    await page.DisplayAlert("Login Error", "Login Error! please try Again", "Ok");
                }
            }
            else
            {
                await page.DisplayAlert("Registration Error", "An Error occured! Please try Again later", "Ok");
            }
        }