Esempio n. 1
0
        private async void Login()
        {
            //comprobamos si esta puesto el email y la contraseña

            if (string.IsNullOrEmpty(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.EmailValidation,
                    Languages.Accept);

                return;
            }
            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PasswordValidation,
                    Languages.Accept);

                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await this.apiService.CheckConnection();

            //si la conexion a internet no ha sido exitosa
            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept);

                return;
            }

            var url = Application.Current.Resources["UrlAPI"].ToString();

            //consumimos el token
            var token = await this.apiService.GetToken(url, this.Email, this.Password);

            //comprobamos si el token es valido o no

            if (token == null || string.IsNullOrEmpty(token.AccessToken))
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.SomethingWrong, Languages.Accept);

                return;
            }

            // si llegamos aquí ya podemos consumir los productos con el token

            Settings.TokenType    = token.TokenType;
            Settings.AccessToken  = token.AccessToken;
            Settings.IsRemembered = this.IsRemembered;

            //OBTENEMOS EL USUARIO
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlUsersController"].ToString();
            var response   = await this.apiService.GetUser(url, prefix, $"{controller}/GetUser", this.Email, token.TokenType, token.AccessToken);

            if (response.IsSuccess)
            {
                var userASP = (MyUserASP)response.Result;
                MainViewModel.GetInstance().UserASP = userASP;
                Settings.UserASP = JsonConvert.SerializeObject(userASP);
            }


            //instanciamos la viewmodel de la page que instanciemos
            MainViewModel.GetInstance().Categories = new CategoriesViewModel();
            Application.Current.MainPage = new MasterPage();

            this.IsRunning = false;
            this.IsEnabled = true;
        }
Esempio n. 2
0
 private async void EditProduct()
 {
     MainViewModel.GetInstance().EditProduct = new EditProductViewModel(this);
     await Application.Current.MainPage.Navigation.PushAsync(new EditProductPage());
 }
Esempio n. 3
0
 private async void Register()
 {
     MainViewModel.GetInstance().Register = new RegisterViewModel();
     await Application.Current.MainPage.Navigation.PushAsync(new RegisterPage());
 }
Esempio n. 4
0
 private async void EditProduct()
 {
     MainViewModel.GetInstance().EditProduct = new EditProductViewModel(this);
     await App.Navigator.PushAsync(new EditProductPage());
 }
Esempio n. 5
0
 private async void GotoCategory()
 {
     MainViewModel.GetInstance().Products = new ProductsViewModel(this);
     await App.Navigator.PushAsync(new ProductsPage());
 }
Esempio n. 6
0
        private async void Login()
        {
            if (string.IsNullOrEmpty(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert(Resource.Error, Resource.EMailError, "Ok");

                return;
            }
            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert(Resource.Error, Resource.PasswordError, "Ok");

                return;
            }
            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;

                await Application.Current.MainPage.DisplayAlert(Resource.Error, connection.Message, "Ok");

                return;
            }

            var urlBase = Application.Current.Resources["UrlApi"].ToString();
            var token   = await apiService.GetToken(urlBase, this.Email, this.Password);

            if (token == null || string.IsNullOrEmpty(token.AccessToken))
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Resource.Error, Resource.SomethingWrong, "Ok");

                return;
            }
            Settings.TokenType    = token.TokenType;
            Settings.AccessToken  = token.AccessToken;
            Settings.IsRemembered = this.IsRemembered;

            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlUsersController"].ToString();
            var response   = await this.apiService.GetUser(urlBase, prefix, $"{controller}/GetUser", this.Email, token.TokenType, token.AccessToken);

            if (response.IsSuccess)
            {
                var userASP = (MyUserASP)response.Result;
                MainViewModel.GetInstance().UserASP = userASP;
                Settings.UserASP = JsonConvert.SerializeObject(userASP);
            }


            MainViewModel.GetInstance().Categories = new CategoriesViewModel();
            Application.Current.MainPage = new MasterPage();

            this.IsRunning = false;
            this.IsEnabled = true;
        }
Esempio n. 7
0
        private async void Login()
        {
            TokenResponse vObjTResponse;

            if (string.IsNullOrEmpty(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.EmailPlaceHolder,
                    Languages.Accept);

                return;
            }

            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PasswordPlaceHolder,
                    Languages.Accept);

                return;
            }
            this.IsRunningActIndicator = true;
            this.IsEnabledcmdLogin     = false;

            var vObjConnection = this.apiService.CheckConnection();

            if (!vObjConnection.IsSuccess)
            {
                this.IsRunningActIndicator = false;
                this.IsEnabledcmdLogin     = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, vObjConnection.Message, Languages.Accept);

                return;
            }

            string vStrUrlAPI = Application.Current.Resources["UrlAPI"].ToString();

            vObjTResponse = await apiService.GetToken(vStrUrlAPI, this.Email, this.Password);

            if (vObjTResponse == null || string.IsNullOrEmpty(vObjTResponse.AccessToken))
            {
                this.IsRunningActIndicator = false;
                this.IsEnabledcmdLogin     = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.AuthError, Languages.Accept);

                return;
            }

            Preferences.TokenType    = vObjTResponse.TokenType;
            Preferences.AccessToke   = vObjTResponse.AccessToken;
            Preferences.IsRemembered = this.IsRemembered;
            Preferences.Email        = this.Email;
            Preferences.PwdEMail     = this.Password;

            MainViewModel.GetInstance().Products = new ProductsViewModel();
            Application.Current.MainPage = new MasterPage();
            this.IsRunningActIndicator   = true;
            this.IsEnabledcmdLogin       = false;
        }
Esempio n. 8
0
        private async void Login()
        {
            if (string.IsNullOrEmpty(Email))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                                Languages.EmailValidation,
                                                                Languages.Accept);


                return;
            }



            if (string.IsNullOrEmpty(Password))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                                Languages.PasswordValidation,
                                                                Languages.Accept);


                return;
            }
            /*check conection*/

            this.IsRunning = true;
            this.IsEnabled = false;


            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSucces)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                                connection.Message,
                                                                Languages.Accept);

                this.IsRunning = false;
                this.IsEnabled = true;
                return;
            }
            /*EL SERVICIO*/

            var url   = Application.Current.Resources["UrlAPI"].ToString();
            var token = await this.apiService.GetToken(url, this.Email, this.password);

            if (token == null || string.IsNullOrEmpty(token.AccessToken))
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                                Languages.SomethingWrong,
                                                                Languages.Accept);


                return;
            }

            Settings.TokenType    = token.TokenType;
            Settings.AccesToken   = token.AccessToken;
            Settings.IsRemembered = this.IsRemembered;


            /**/
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlUsersController"].ToString();
            var response   = await this.apiService.GetUser(url, prefix, $"{controller}/GetUser", this.Email, token.TokenType, token.AccessToken);

            if (response.IsSucces)
            {
                var userASP = (MyUserASP)response.Result;
                MainViewModel.GetInstance().UserASP = userASP;
                Settings.UserASP = JsonConvert.SerializeObject(userASP);
            }


            /**/

            MainViewModel.GetInstance().Products = new ProductsViewModel();
            Application.Current.MainPage = new MasterPage();//ProductsPage();


            this.IsRunning = false;
            this.IsEnabled = true;
        }
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept);

                return;
            }

            if (string.IsNullOrEmpty(this.Price))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);

                return;
            }

            var price = decimal.Parse(this.Price);

            if (price < 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);

                return;
            }

            if (this.Category == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.CategoryError,
                    Languages.Accept);

                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    connection.Message,
                    Languages.Accept);

                return;
            }

            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            var location = await this.GetLocation();

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
                CategoryId  = this.Category.CategoryId,
                UserId      = MainViewModel.GetInstance().UserASP.Id,
                Latitude    = location == null ? 0 : location.Latitude,
                Longitude   = location == null ? 0 : location.Longitude,
            };

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();
            var response   = await this.apiService.Post(url, prefix, controller, product, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            var newProduct        = (Product)response.Result;
            var productsViewModel = ProductsViewModel.GetInstance();

            productsViewModel.MyProducts.Add(newProduct);
            productsViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();
        }
Esempio n. 10
0
        private async void Login()
        {
            if (string.IsNullOrEmpty(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.EmailValidation,
                    Languages.Accept
                    );

                return;
            }
            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PasswordValidation,
                    Languages.Accept
                    );

                return;
            }

            this.IsRunning = true;  // Muestra el Activity indicator
            this.IsEnabled = false; // Desabilita botones
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    connection.Message,
                    Languages.Accept
                    );

                return;
            }

            var url   = Application.Current.Resources["UrlAPI"].ToString() + "/"; // Obtengo la url del diccionario de recursos.
            var token = await this.apiService.GetToken(url, this.Email, this.Password);

            if (token == null || string.IsNullOrEmpty(token.AccessToken))
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.SomethingWrong,
                    Languages.Accept
                    );

                return;
            }

            Settings.TokenType    = token.TokenType;
            Settings.AccessToken  = token.AccessToken;
            Settings.IsRemembered = this.IsRemembered;

            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlUsersController"].ToString();
            var response   = await this.apiService.GetUser(url, prefix, $"{controller}/GetUser", this.Email, token.TokenType, token.AccessToken);

            if (response.IsSuccess)
            {
                var userASP = (MyUserASP)response.Result;
                MainViewModel.GetInstance().UserASP = userASP;
                Settings.UserASP = JsonConvert.SerializeObject(userASP);
            }

            //MainViewModel.GetInstance().Products = new ProductsViewModel();
            MainViewModel.GetInstance().Categories = new CategoriesViewModel();
            Application.Current.MainPage = new MasterPage();

            this.IsRunning = false;
            this.IsEnabled = true;
        }
Esempio n. 11
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept);

                return;
            }

            if (string.IsNullOrEmpty(this.Price))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);

                return;
            }

            var price = decimal.Parse(this.Price);

            if (price < 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);

                return;
            }

            if (this.Category == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.CategoryError,
                    Languages.Accept);

                return;
            }

            this.IsRunning = true;  // Esto muestra el activity indicator
            this.IsEnabled = false; // Desabilito el botón de SAVE para que el usuario no le pegue varias veces.


            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    connection.Message,
                    Languages.Accept);

                return;
            }

            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            var location = await this.GetLocation();

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
                CategoryId  = this.Category.CategoryId,
                UserId      = MainViewModel.GetInstance().UserASP.Id,
                Latitude    = location == null ? 0 : location.Latitude,
                Longitude   = location == null ? 0 : location.Longitude,
            };


            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();
            var response   = await this.apiService.Post(url, prefix, controller, product, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            /*
             *   Agregamos el producto en la ListView.
             *   NOTA: El producto que enviamos no tiene fecha, ni IsAvailable,
             *   ni el Id del producto, en cambio, cuando va a la api y vuelve, ya trae todos esos datos.
             */

            var newProduct        = (Product)response.Result;
            var productsViewModel = ProductsViewModel.GetInstance();

            productsViewModel.MyProducts.Add(newProduct);
            productsViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();
        }
Esempio n. 12
0
        private async void Goto()
        {
            if (this.PageName == "LoginPage")
            {
                Settings.AccessToken  = string.Empty;
                Settings.TokenType    = string.Empty;
                Settings.IsRemembered = false;

                MainViewModel.GetInstance().Login = new LoginViewModel();
                Application.Current.MainPage = new NavigationPage(new LoginPage());
            }/*
              * else if (this.PageName =="AboutPage")
              * {
              * //para que oculte la master page
              * App.Master.IsPresented = false;
              * await App.Navigator.PushAsync(new MapPage());
              * }*/
            else if (this.PageName == "Presentation")
            {
                //para que oculte la master page
                App.Master.IsPresented = false;
                await App.Navigator.PushAsync(new Presentacion());
            }
            else if (this.PageName == "Contact")
            {
                //para que oculte la master page
                App.Master.IsPresented = false;
                MainViewModel.GetInstance().Contact = new ContactViewModel();
                //Application.Current.MainPage = new NavigationPage(new Contact());
                await App.Navigator.PushAsync(new Contact());
            }
            else if (this.PageName == "Paciente")
            {
                //para que oculte la master page
                App.Master.IsPresented = false;
                //MainViewModel.GetInstance().Contact = new ContactViewModel();
                //Application.Current.MainPage = new NavigationPage(new Contact());

                await App.Navigator.PushAsync(new AthletePage(MainViewModel.GetInstance().UserASP.Email));
            }
            else if (this.PageName == "Exercises")
            {
                //para que oculte la master page
                App.Master.IsPresented = false;
                //MainViewModel.GetInstance().Contact = new ContactViewModel();
                //Application.Current.MainPage = new NavigationPage(new Contact());
                MainViewModel.GetInstance().Categories = new CategoriesViewModel();
                //Application.Current.MainPage = new NavigationPage(new LoginPage());
                await App.Navigator.PushAsync(new CategoriesPage());
            }
            else if (this.PageName == "Videos")
            {
                //para que oculte la master page
                App.Master.IsPresented = false;
                //MainViewModel.GetInstance().Contact = new ContactViewModel();
                //Application.Current.MainPage = new NavigationPage(new Contact());
                MainViewModel.GetInstance().Videos = new VideosViewModel();
                //Application.Current.MainPage = new NavigationPage(new LoginPage());
                await App.Navigator.PushAsync(new VideosPage());
            }

            else if (this.PageName == "Financiacion")
            {
                //para que oculte la master page
                App.Master.IsPresented = false;
                //MainViewModel.GetInstance().Contact = new ContactViewModel();
                //Application.Current.MainPage = new NavigationPage(new Contact());
                //MainViewModel.GetInstance().Videos = new VideosViewModel();
                //Application.Current.MainPage = new NavigationPage(new LoginPage());
                await App.Navigator.PushAsync(new Financiacion());
            }
        }