private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Delete,
                Languages.DeleteConfirmed,
                Languages.Yes,
                Languages.No);


            if (!answer)
            {
                return;
            }

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

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


                return;
            }


            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.Delete(
                url,                                                                  /*"http://192.168.1.79:16094*/
                prefix,                                                               /*/api*/
                controller, this.ProductId, Settings.TokenType, Settings.AccesToken); /*Products*/


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

                return;
            }



            var productsViewModel = ProductsViewModel.GetInstance();
            var deleteProduct     = productsViewModel.Products.Where(p => p.ProductId == this.ProductId).FirstOrDefault();

            if (deleteProduct != null)
            {
                productsViewModel.Products.Remove(deleteProduct);
            }
        }
Beispiel #2
0
        private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes,
                Languages.No);

            if (!answer)
            {
                return;
            }
            //eliminamos el producto
            //comprobamos si hay conexión
            var connection = await this.apiService.CheckConnection();

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

                return;
            }

            //vamos a la api
            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.Delete(url, prefix, controller, this.ProductId, Settings.TokenType, Settings.AccessToken);

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

                return;
            }

            //hay que actualizar la lista, llamamos a  SINGLETON
            var productsViewModel = ProductsViewModel.GetInstance();

            //buscamos el producto en la lista y lo eliminamos
            var deletedProduct = productsViewModel.MyProducts.Where(p => p.ProductId == this.ProductId).FirstOrDefault();

            //si encontramos el producto
            if (deletedProduct != null)
            {
                productsViewModel.MyProducts.Remove(deletedProduct);
            }
            productsViewModel.RefreshList();
        }
Beispiel #3
0
        private async void Delete()
        {
            var answer = await App.Navigator.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes,
                Languages.No);

            if (!answer)
            {
                return;
            }

            this.IsRunning = true;
            this.isEnable  = false;
            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.isEnable  = true;
                await App.Navigator.DisplayAlert(Languages.Error, connection.Message, Languages.Accept);

                return;
            }
            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.Delete(url, prefix, controller, this.Product.ProductId, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.isEnable  = true;
                await App.Navigator.DisplayAlert(Languages.Error, response.Message, "Accept");

                return;
            }


            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.MyProducts.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productsViewModel.MyProducts.Remove(deletedProduct);
            }
            productsViewModel.RefreshList();

            this.IsRunning = false;
            this.isEnable  = true;
            await App.Navigator.Navigation.PopAsync();
        }
Beispiel #4
0
        private async void Delete()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes, Languages.No);

            if (!answer)
            {
                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;
            }
            //agregar al diccionarion de recursos ap.xaml la direccion URL por seguridad
            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.Delete(url, prefix, controller, this.Product.ProductId, Settings.TokkenType, Settings.AccessToken);

            //aca devolvio una lista de obj. response
            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept);

                return;
            }
            //refrescar la lista
            //llamar el singleton
            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.MyProducts.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productsViewModel.MyProducts.Remove(deletedProduct);
            }
            productsViewModel.RefreshList();
            this.IsRunning = false;
            this.IsEnabled = true;
            await Application.Current.MainPage.Navigation.PopAsync();
        }
        private async void Delete()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes,
                Languages.No);

            if (!answer)
            {
                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;
            }

            var response = await this.apiService.Delete("https://salesapijonalexjm.azurewebsites.net", "/api", "/Products", this.Product.ProductId);


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

                return;
            }

            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.Products.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productsViewModel.Products.Remove(deletedProduct);
            }

            productsViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await Application.Current.MainPage.Navigation.PopAsync();
        }
        private async void Delete()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                "Confirm",
                "Are you sure to delete this record?",
                "Yes",
                "No");

            if (!answer)
            {
                return;
            }

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

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

                return;
            }

            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.Delete(url, prefix, controller, this.ProductId);

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

                return;
            }

            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.Products.
                                    Where(p => p.ProductId == this.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productsViewModel.Products.Remove(deletedProduct);
            }
        }
Beispiel #7
0
        private async void DeleteProducts()
        {
            var vAnswer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes,
                Languages.No
                );

            if (vAnswer == false)
            {
                return;
            }
            this.IsRunningActIndicator = true;
            this.IsEnabledCmdSave      = false;

            var vObjConnection = this.apiService.CheckConnection();

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

                return;
            }

            string vStrUrlAPI                = Application.Current.Resources["UrlAPI"].ToString();
            string vStrUrlAPIPrefix          = Application.Current.Resources["APIPrefix "].ToString();
            string vStrUrlProductsController = Application.Current.Resources["ProductsController"].ToString();
            var    response = await this.apiService.Delete(vStrUrlAPI, vStrUrlAPIPrefix, vStrUrlProductsController, this.ProductItemViewModel.ProductID, Preferences.TokenType, Preferences.AccessToke);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.Confirm, Languages.Accept);

                return;
            }
            ProductsViewModel vProductsViewModel = ProductsViewModel.GetInstance();
            var vDeleteProd = vProductsViewModel.vObjList.Where(Prod => Prod.ProductID == this.ProductItemViewModel.ProductID).FirstOrDefault();

            if (vDeleteProd != null)
            {
                vProductsViewModel.vObjList.Remove(vDeleteProd);
            }

            vProductsViewModel.RefreshListProducts();
            await App.Navigator.PopAsync();
        }
        private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.yes,
                Languages.No);

            if (!answer)
            {
                return;
            }

            var connection = await apiService.CheckConnection();

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

                return;
            }

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();
            var response   = await apiService.Delete(url, prefix, controller, ProductId);

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

                return;
            }

            var productsViewModel = ProductsViewModel.GetInstce();
            var deletedProdcut    = productsViewModel.Products.Where(p => p.ProductId == ProductId).FirstOrDefault();

            if (deletedProdcut != null)
            {
                productsViewModel.Products.Remove(deletedProdcut);
            }
        }
        private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.ConfirmDelete,
                Languages.Yes,
                Languages.No);

            if (!answer)
            {
                return;
            }


            //checamos la conexion

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

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

                return;
            }

            var url                = Application.Current.Resources["UrlApi"].ToString();
            var prefix             = Application.Current.Resources["UrlPrefix"].ToString();
            var productsController = Application.Current.Resources["UrlProductsController"].ToString();
            var response           = await this.apiService.Delete(url, prefix, productsController, this.ProductId);

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

                return;
            }


            //para refrescar la lista despues de eliminar un registro de la base de datos.
            var productViewModel = ProductsViewModel.GetInstance();
            var deletedProduct   = productViewModel.Products.Where(p => p.ProductId == this.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productViewModel.Products.Remove(deletedProduct);
            }
        }
Beispiel #10
0
        private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes,
                Languages.No);

            if (!answer)
            {
                return;
            }

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

            if (!connection.IsSuccess)
            {
                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 prefix     = Application.Current.Resources["UrlPrefix"].ToString();             // Obtengo el prefijo del diccionario de recursos.
            var controller = Application.Current.Resources["UrlProductsController"].ToString(); // Obtengo el controlador del diccionario de recursos.

            var response = await this.apiService.Delete(url, prefix, controller, this.ProductId, Settings.TokenType, Settings.AccessToken);

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

                return;
            }

            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.MyProducts.Where(p => p.ProductId == this.ProductId).FirstOrDefault(); // LinQ

            if (deletedProduct != null)
            {
                productsViewModel.MyProducts.Remove(deletedProduct); // con esto me lo debe refrescar automaticamente en la lista
            }
            productsViewModel.RefreshList();
        }
Beispiel #11
0
        private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Resource.Confirm,
                Resource.DeleteConfirmation,
                Resource.Yes,
                Resource.No);

            if (!answer)
            {
                return;
            }
            var connection = await apiService.CheckConnection();

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

                return;
            }

            var urlBase       = Application.Current.Resources["UrlApi"].ToString();
            var urlPrefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var urlController = Application.Current.Resources["UrlProductsController"].ToString();
            var response      = await this.apiService.Delete(urlBase, urlPrefix, urlController, this.ProductId, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(Resource.Error, response.Message, "Ok");

                return;
            }

            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.MyProducts.Where(p => p.ProductId == this.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productsViewModel.MyProducts.Remove(deletedProduct);
            }
            productsViewModel.RefreshList();
        }
Beispiel #12
0
        private async void DeleteProduct()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(
                Languages.Confirm,
                Languages.DeleteConfirmation,
                Languages.Yes,
                Languages.No);

            if (!answer)
            {
                return;
            }

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

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

                return;
            }

            var response = await this.apiService.Delete("https://salesapijonalexjm.azurewebsites.net", "/api", "/Products", this.ProductId, Settings.TokenType,
                                                        Settings.AccessToken);


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

                return;
            }

            var productsViewModel = ProductsViewModel.GetInstance();
            var deletedProduct    = productsViewModel.Products.Where(p => p.ProductId == this.ProductId).FirstOrDefault();

            if (deletedProduct != null)
            {
                productsViewModel.Products.Remove(deletedProduct);
            }
        }
Beispiel #13
0
 public MainViewModel()
 {
     this.Products = new ProductsViewModel();
 }
Beispiel #14
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Product.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept);

                return;
            }

            if (this.Product.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());
                this.product.ImageArray = imageArray;
            }

            this.Product.CategoryId = this.Category.CategoryId;

            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.Put(url, prefix, controller, this.product, this.Product.ProductId, 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;
            }

            /*
             *   Refrescamos la ListView eliminado y agregando el producto.
             *   (Es la unica manera en que refresca. Bug de xamarin)
             */

            var newProduct        = (Product)response.Result;
            var productsViewModel = ProductsViewModel.GetInstance();
            var oldProduct        = productsViewModel.MyProducts.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (oldProduct != null)
            {
                productsViewModel.MyProducts.Remove(oldProduct);
            }

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


            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();
        }
Beispiel #15
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;
            }
            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;
            }
            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
            };
            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);

            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 viewModel  = ProductsViewModel.GetInstance();

            viewModel.Products.Add(newProduct);
            this.isRunning = false;
            this.IsEnabled = true;
            await Application.Current.MainPage.Navigation.PopAsync();
        }
Beispiel #16
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.description))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                                Languages.DescriptionError,
                                                                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 (string.IsNullOrEmpty(this.remarks))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                                "Please Insert a Remarks",
                                                                Languages.Accept);


                return;
            }

            /*check Connection*/
            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;
            }

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();


            /*para la camara*/

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

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
                PublishOn   = DateTime.Now,
            };



            var response = await this.apiService.Post(
                url,                                                           /*"http://192.168.1.79:16094*/
                prefix,                                                        /*/api*/
                controller, product, Settings.TokenType, Settings.AccesToken); /*Products*/



            if (!response.IsSucces)
            {
                this.isRunning = false;
                this.isEnabled = true;

                await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept);

                return;
            }


            var newProduct        = (Product)response.Result;        /*locasteamos*/
            var productsViewModel = ProductsViewModel.GetInstance(); /*de esta manera se actualiza la lista de productos cuandose agraga uno nuevo*/

            productsViewModel.MyProducts.Add(newProduct);

            productsViewModel.RefreshList();


            //productsViewModel.Products.Add(new ProductItemViewModel
            //{
            //    Description = newProduct.Description,
            //    ImageArray = newProduct.ImageArray,
            //    ImagePath = newProduct.ImagePath,
            //    IsAvailable = newProduct.IsAvailable,
            //    Price = newProduct.Price,
            //    ProductId = newProduct.ProductId,
            //    PublishOn = newProduct.PublishOn,
            //    Remarks = newProduct.Remarks,
            //});
            // viewModel.Products.Add(newProduct);/*y se realiza para no volver ha realizar un llamado al server*/


            this.isRunning = false;
            this.isEnabled = true;

            //await Application.Current.MainPage.Navigation.PopAsync();/*para desapilar */
            await App.Navigator.PopAsync();
        }
Beispiel #17
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Aceptar);

                return;
            }

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

                return;
            }

            var price = decimal.Parse(Price);

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

                return;
            }

            IsRunning = true;
            isEnabled = false;

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

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

                return;
            }

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

            var product = new Product
            {
                Description = Description,
                Price       = price,
                Remarks     = Remarks,
                ImageArray  = imageArray,
            };
            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);

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

                return;
            }

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

            productsViewModel.MyProducts.Add(newProduct);
            productsViewModel.RefreshList();
            IsRunning = false;
            isEnabled = true;
            await Application.Current.MainPage.Navigation.PopAsync();
        }
        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;
            }
            this.IsRunning = true;
            this.IsEnabled = false;
            var connection = await this.apiService.CheckConnection();

            if (!connection.isSucess)
            {
                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 product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
            };

            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);

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

                return;
            }

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

            viewModel.Products.Add(new ProductItemViewModel
            {
                Description = newProduct.Description,
                ImageArray  = newProduct.ImageArray,
                ImagePath   = newProduct.ImagePath,
                IsAvailable = newProduct.IsAvailable,
                Price       = newProduct.Price,
                ProductId   = newProduct.ProductId,
                PublishOn   = newProduct.PublishOn,
                Remarks     = newProduct.Remarks,
            });



            this.isRunning = false;
            this.isEnabled = true;
            await Application.Current.MainPage.Navigation.PopAsync();
        }
Beispiel #19
0
        //Método para grabar los datos en el WebAPI, previa validación
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Description))
            {
                _ = Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                              Languages.DescriptionError,
                                                              Languages.Accept);
                return;
            }

            if (string.IsNullOrEmpty(this.Price))
            {
                _ = Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                              Languages.PriceError,
                                                              Languages.Accept);
                return;
            }

            decimal price = Convert.ToDecimal(this.Price);

            if (price < 0)
            {
                _ = Application.Current.MainPage.DisplayAlert(Languages.Error,
                                                              Languages.PriceError,
                                                              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;
            }

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
            };

            string url                = Application.Current.Resources["UrlAPI"].ToString();
            string prefix             = Application.Current.Resources["UrlPrefix"].ToString();
            string productsController = Application.Current.Resources["UrlProductsController"].ToString();
            var    response           = await this.ApiService.Post(url, prefix, productsController, product);

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

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

            viewModel.Products.Add(newProduct);
            var list = viewModel.Products.OrderBy(p => p.Description).ToList();

            viewModel.Products = new ObservableCollection <Product>(list);

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

            await Application.Current.MainPage.Navigation.PopAsync();

            /* ALTERNATIVA PARA REFRESCAR
             * ICommand comando;
             * comando = ProductsViewModel.GetInstance().RefreshCommand;
             * comando.Execute(null);*/
        }
Beispiel #20
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;
            }


            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 = FileHelper.ReadFully(this.file.GetStream());
            }

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
            };

            var response = await this.apiService.Post(
                "https://salesapijonalexjm.azurewebsites.net",
                "/api",
                "/Products",
                product,
                Settings.TokenType,
                Settings.AccessToken);

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

                return;
            }

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

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


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

            await App.Navigator.PopAsync();// navega a la pagina pricipal
        }
Beispiel #21
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Product.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept);

                return;
            }

            /*
             * if (this.Product.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;

            //chekea la conexion
            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;
            }

            //para saber si se cogió o no foto
            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
                this.Product.ImageArray = imageArray;
            }

            //por si el usuario cambia la categoría
            this.Product.CategoryId = this.Category.CategoryId;

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

            var prefix = Application.Current.Resources["UrlPrefix"].ToString();

            var controller = Application.Current.Resources["UrlProductsController"].ToString();

            //invocamos el metodo post del apiservice
            var response = await this.apiService.Put(url, prefix, controller, this.Product, this.Product.ProductId, Settings.TokenType, Settings.AccessToken);

            //preguntamos si lo grabó de manera exitosa
            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;

            //adicionamos el producto a la colección
            var productsViewModel = ProductsViewModel.GetInstance();

            //buscamos el producto lo eliminamos y lo volvemos a crear
            var oldProduct = productsViewModel.MyProducts.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (oldProduct != null)
            {
                productsViewModel.MyProducts.Remove(oldProduct);
            }


            productsViewModel.MyProducts.Add(newProduct);
            productsViewModel.RefreshList();
            // la ordenamos
            //viewModel.Products = viewModel.Products.OrderBy(p => p.Description).ToList();


            //si lo hizo de manera exitosa hacemos el back
            this.IsRunning = false;
            this.IsEnabled = true;
            //Desapilamos
            await App.Navigator.PopAsync();
        }
Beispiel #22
0
        private async void Save()
        {
            this.IsEnabled = true;
            this.IsRunning = true;
            if (string.IsNullOrEmpty(this.Description))
            {
                this.IsRunning = false;
                await Application.Current.MainPage.DisplayAlert("Error", "Please, add a description", "Appect");

                return;
            }

            if (string.IsNullOrEmpty(this.Price))
            {
                this.IsRunning = false;
                await Application.Current.MainPage.DisplayAlert("Error", "Please, add a price", "Appect");

                return;
            }

            try
            {
                var p = decimal.Parse(this.Price);
            }
            catch
            {
                this.IsRunning = false;
                await Application.Current.MainPage.DisplayAlert("Error", "Price format incorrect", "Appect");

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

            if (price <= 0)
            {
                this.IsRunning = false;
                await Application.Current.MainPage.DisplayAlert("Error", "Please, add a positive price", "Appect");

                return;
            }

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

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

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

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

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
            };

            var response = await this.apiService.Post <Product>("http://10.0.4.113", "/SalesApi/api", "/Products", product);

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

                return;
            }

            //if (response.IsSuccess)
            //{
            //    await Application.Current.MainPage.DisplayAlert("","Done!","Ok");
            //}

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

            viewModel.Products.Add(ToProductItemViewModel(newProduct));


            await App.Navigator.PopAsync();


            //apiService.Post<>();
        }
Beispiel #23
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;
            }

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

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

            if (!connection.IsSuccess)
            {
                this.IsEnabled = true;
                this.IsRunning = false;
                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 product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
            };

            //var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            //var response = await this.apiService.Post(
            //    apiSecurity,
            //    "/api",
            //    "/Users",
            //    user);


            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);

            // the code below also works when adding a new product. just uncomment the url  and the response vars.
            // var url = Application.Current.Resources["UrlAPI"].ToString();
            // var response = await this.apiService.Post(url, "/api", "/Products", product);

            if (!response.IsSuccess)
            {
                this.IsEnabled = true;
                this.IsRunning = false;
                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.IsEnabled = true;
            this.IsRunning = false;
            await App.Navigator.PopAsync();
        }
Beispiel #24
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;
            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();

            // desapilar
            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();
        }
Beispiel #25
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(Product.Description))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.DescriptionError, Languages.Accept);

                return;
            }

            if (this.Product.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;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    connection.Message,
                    Languages.Accept
                    );

                //await Application.Current.MainPage.Navigation.PopAsync();
                await App.Navigator.PopAsync();

                return;
            }

            this.Product.CategoryId = this.Category.CategoryId;

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();


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

            var response = await this.apiService.Put(
                url,
                prefix,
                controller,
                this.Product,
                this.Product.ProductId,
                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 ProductsViewModelInstance = ProductsViewModel.GetInstance();

            var oldProduct =
                ProductsViewModelInstance.MyProducts.Where(
                    p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (oldProduct != null)
            {
                ProductsViewModelInstance.MyProducts.Remove(oldProduct);
            }

            var newProduct = (Product)response.Result;

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

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

            //await Application.Current.MainPage.Navigation.PopAsync();
            await App.Navigator.PopAsync();
        }
Beispiel #26
0
        private async void AddProducts()
        {
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.AddProdDescError,
                    Languages.Accept);

                return;
            }

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

                return;
            }

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

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

                return;
            }

            this.IsRunningActIndicator = true;
            this.IsEnabledCmdSave      = false;

            var vObjConnection = this.apiService.CheckConnection();

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

                return;
            }

            string vStrUrlAPI                = Application.Current.Resources["UrlAPI"].ToString();
            string vStrUrlAPIPrefix          = Application.Current.Resources["APIPrefix "].ToString();
            string vStrUrlProductsController = Application.Current.Resources["ProductsController"].ToString();

            byte[] vImageArray = null;
            if (vImageFile != null)
            {
                vImageArray = FileHelper.ReadFully(this.vImageFile.GetStream());
            }

            Product vObProduct = new Product {
                Description = this.Description,
                Price       = vPrice,
                Notes       = this.Notes,
                ImageArray  = vImageArray,
            };

            var vResponse = await apiService.Post(vStrUrlAPI, vStrUrlAPIPrefix, vStrUrlProductsController, vObProduct, Preferences.TokenType, Preferences.AccessToke);

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

                return;
            }

            Product vNewProducts = (Product)vResponse.Result;
            //var vNewProductsItem = new Products.ProductItemViewModel
            //{
            //    ProductID = vNewProducts.ProductID,
            //    Description = vNewProducts.Description,
            //    Notes = vNewProducts.Notes,
            //    Price = vNewProducts.Price,
            //    IsAvailable = vNewProducts.IsAvailable,
            //    PublishOn = vNewProducts.PublishOn,
            //    ImageArray = vNewProducts.ImageArray,
            //    ImagePath = vNewProducts.ImagePath,
            //};
            ProductsViewModel vProductsViewModel = ProductsViewModel.GetInstance();

            //vProductsViewModel.ListProducts.Add(vNewProductsItem);
            vProductsViewModel.vObjList.Add(vNewProducts);
            vProductsViewModel.RefreshListProducts();
            this.IsRunningActIndicator = false;
            this.IsEnabledCmdSave      = true;
            await App.Navigator.PopAsync();
        }
Beispiel #27
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;
            }
            //activar el activity indicator y apagar el boton por los chequeos  conexion
            this.IsRunning = true;
            this.IsEnabled = false;
            //chequea conexion
            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;
            }
            //SI EL USUARIO SELECCIONO FOTO O LA TOMO
            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            //ARMAMOS EL OBJETOS con los valores que ingreso el usuario en el formulario
            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                //convierte la imagen a un string  base 64
                ImageArray = imageArray,
            };

            //consumir el API
            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();
            //NOTA el VS simplifica el nombre Post y no se coloca en la notacion diamante Product
            //pues ya esta dentro de los parametros.
            var response = await this.apiService.Post(url, prefix, controller, product, Settings.TokkenType, Settings.AccessToken);

            //preguntar si lo grabo
            if (!response.IsSuccess)
            {
                //la propiedad
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }
            //casteamos de la clase products y nos devuelve el servicio
            var newProduct = (Product)response.Result;
            //adicionarle a ese producto a la obserbable collections
            //llamado el patron SIGLETON
            var productsviewModel = ProductsViewModel.GetInstance();

            productsviewModel.MyProducts.Add(newProduct);
            //invocamos el refresco para la lista ordenada
            productsviewModel.RefreshList();
            //VIEWMODEL tiene la coleccion de productos y se debe adicionar


            //devolvernos al listado  por codigo un back
            this.IsRunning = false;
            this.IsEnabled = true;
            //hacer un desapilamiento entre las PAGE (para regresar a listado de productos PAGE)
            // await Application.Current.MainPage.Navigation.PopAsync();
            await App.Navigator.PopAsync();
        }
Beispiel #28
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Product.Description))
            {
                await Application.Current.MainPage.DisplayAlert(Resource.Error, Resource.DescriptionError, "Ok");

                return;
            }
            if (this.Product.Price <= 0)
            {
                await Application.Current.MainPage.DisplayAlert(Resource.Error, Resource.PriceError, "Ok");

                return;
            }

            if (this.Category == null)
            {
                await Application.Current.MainPage.DisplayAlert(Resource.Error, Resource.CategoryError, "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;
            }

            this.Product.CategoryId = this.Category.CategoryId;
            var urlBase       = Application.Current.Resources["UrlApi"].ToString();
            var urlPrefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var urlController = Application.Current.Resources["UrlProductsController"].ToString();

            if (this.file != null)
            {
                this.product.ImageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            var response = await this.apiService.Put <Product>(urlBase, urlPrefix, urlController, this.Product, this.Product.ProductId, Settings.TokenType, Settings.AccessToken);

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

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

                return;
            }

            var updatedProduct    = (Product)response.Result;
            var productsViewModel = ProductsViewModel.GetInstance();
            var oldProduct        = productsViewModel.MyProducts.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (oldProduct != null)
            {
                productsViewModel.MyProducts.Remove(oldProduct);
            }

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

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

            await App.Navigator.PopAsync();
        }
Beispiel #29
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Product.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept);
            }


            if (this.Product.Price < 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);
            }

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

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

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

                return;
            }

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

            var urlAPI               = Application.Current.Resources["UrlAPI"].ToString();
            var urlPrefix            = Application.Current.Resources["UrlPrefix"].ToString();
            var urlProductController = Application.Current.Resources["UrlProductController"].ToString();
            var response             = await apiService.Put(urlAPI, urlPrefix, urlProductController, this.product, this.product.ProductId);

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

                return;
            }
            // Add product no refresh using singleton.
            var newProduct        = (Product)response.Result;
            var productsViewModel = ProductsViewModel.GetInstance();

            var oldProduct = productsViewModel.MyProducts.Where(p => p.ProductId == this.Product.ProductId).FirstOrDefault();

            if (oldProduct != null)
            {
                productsViewModel.MyProducts.Remove(oldProduct);
            }

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

            this.IsRunning = false;
            this.IsEnabled = true;
            await Application.Current.MainPage.Navigation.PopAsync();
        }
Beispiel #30
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;
            this.IsEnabled = false;

            //chekea la conexion
            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;
            }

            //para saber si se cogió o no foto
            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            // var location = await this.GetLocation();

            //metemos lo que mandemos al post como un producto
            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();

            //invocamos el metodo post del apiservice
            var response = await this.apiService.Post(url, prefix, controller, product, Settings.TokenType, Settings.AccessToken);

            //preguntamos si lo grabó de manera exitosa
            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;

            //adicionamos el producto a la colección
            var productsViewModel = ProductsViewModel.GetInstance();

            productsViewModel.MyProducts.Add(newProduct);
            productsViewModel.RefreshList();
            // la ordenamos
            //viewModel.Products = viewModel.Products.OrderBy(p => p.Description).ToList();


            //si lo hizo de manera exitosa hacemos el back
            this.IsRunning = false;
            this.IsEnabled = true;
            //Desapilamos
            await App.Navigator.PopAsync();
        }