Example #1
0
        private async void Login()
        {
            IsRunning = true;
            if (string.IsNullOrEmpty(Email))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Ingrese su correo electronico",
                    "Ok");

                return;
            }
            if (string.IsNullOrEmpty(Password))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Ingrese su contraseƱa",
                    "Ok");

                return;
            }
            IsRunning = true;

            //Verificando conexion a internet
            var connection = await connectionService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    connection.Message,
                    "Ok");

                Password = string.Empty;
                await Application.Current.MainPage.Navigation.PopAsync();

                return;
            }
            //Consumiendo api para loguearse
            var login = await apiService.Login(Email, Password);

            if (!login.IsSuccess)
            {
                IsRunning = false;
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    login.Message,
                    "Ok");

                Password = string.Empty;
                return;
            }

            Application.Current.MainPage = new NavigationPage(new MainPage());
            IsRunning = false;
            Email     = string.Empty;
            Password  = string.Empty;
        }