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(); //si no hay conexión le pintamos un mensaje al usuario 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();*/ //la url está en una llave en el App.xaml var response = await this.apiService.Delete("http://salesapi.somee.com/", "/api", "/ProductsLuis", this.Product.CVE_PRODUCTO_VAR, Settings.TokenType, Settings.AccessToken); //no hay lista de productos if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } var productsViewModel = ProductsLuisViewModel.GetInstance(); var deleteProduct = productsViewModel.MyProducts.Where(p => p.CVE_PRODUCTO_VAR == this.Product.CVE_PRODUCTO_VAR).FirstOrDefault(); if (deleteProduct != null) { productsViewModel.MyProducts.Remove(deleteProduct); } productsViewModel.RefreshList(); this.IsRunning = false; this.IsEnabled = true; await App.Navigator.PopAsync(); }
private async void Save() { //clave del producto vacía if (string.IsNullOrEmpty(this.KeyProduct)) { await Application.Current.MainPage.DisplayAlert ( Languages.Error, Languages.KeyProduct, Languages.Accept ); return; } //nombre del producto vacío if (string.IsNullOrEmpty(this.Name)) { await Application.Current.MainPage.DisplayAlert ( Languages.Error, Languages.DescriptionError, Languages.Accept ); return; } //precio vacío if (string.IsNullOrEmpty(this.Price)) { await Application.Current.MainPage.DisplayAlert ( Languages.Error, Languages.PriceError, Languages.Accept ); return; } //precio menor o igual a cero var price = decimal.Parse(this.Price); if (price <= 0) { await Application.Current.MainPage.DisplayAlert ( Languages.Error, Languages.PriceError, Languages.Accept ); return; } //unidad de medida vacía if (string.IsNullOrEmpty(UnitOfMeasurement)) { await Application.Current.MainPage.DisplayAlert ( Languages.Error, Languages.UnitOfMeasurement, Languages.Accept ); return; } this.IsRunning = true; this.IsEnabled = false; //checamos si el cel tiene conexión a internet 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; } //checamos si el usuario seleccionó una imagen // si es así la convertimos en un array de bites byte[] imageArray = null; if (this.file != null) { imageArray = FileHelper.ReadFully(this.file.GetStream()); } //vamos a agregar un nuevo producto var product = new ProductsLuis { CVE_PRODUCTO_VAR = KeyProduct, NOM_PROD_VAR = this.Name, PRECIO_DEC = price, REMARK_VAR = this.Remarks, UNIDAD_MEDIDA_VAR = this.UnitOfMeasurement, ImageArray = imageArray, }; //enviamos el nuevo producto /* var url = Application.Current.Resources["urlApi"].ToString();*/ //la url está en una llave en el ApnewProduct.xaml var response = await this.apiService.PostList("http://salesapi.somee.com/", "/api", "/ProductsLuis", 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; } // cargamos el nuevo producto para mostrarlo en la página principal de productos var newProduct = (ProductsLuis)response.Result; var productsLuisViewModel = ProductsLuisViewModel.GetInstance(); productsLuisViewModel.MyProducts.Add(newProduct); productsLuisViewModel.RefreshList(); this.IsRunning = false; this.IsEnabled = true; //volvemos a la página principal await App.Navigator.PopAsync(); }