async void SaveCommandMethod() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter a category description... "); } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } Category category = new Category() { Description = Description }; var mainViewModel = MainViewModel.GetInstance(); var apiServiceWithoutConection = (ApiServiceWithoutConnection)apiService; var response = await apiServiceWithoutConection.PostCategory( "http://productszuluapi.azurewebsites.net", "/api", "/Categories", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, category); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } category = (Category)response.Result; var categoryViewModel = CategoriesViewModel.GetInstance(); categoryViewModel.AddCategory(category); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter a category description."); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", connection.Message); return; } category.Description = Description; var mainViewModel = MainViewModel.GetInstance(); var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService.Put( urlAPI, "/api", "/Categories", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, category); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } var categoriesViewModel = CategoriesViewModel.GetInstance(); categoriesViewModel.Update(category); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
public static CategoriesViewModel GetInstance() { if (instance == null) { instance = new CategoriesViewModel(); } return(instance); }
private async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage(Languages.Error, Languages.NewCategoryError); return; } IsRunning = true; IsEnable = false; var connection = await apiService.CheckConnection(); if (!connection.isSuccess) { IsRunning = false; IsEnable = true; await dialogService.ShowMessage(Languages.Error, connection.Message); return; } var category = new Category { Description = Description }; var mainViewModel = MainViewModel.GetInstance(); var response = await apiService.Post( Application.Current.Resources["URLAPI"].ToString(), Application.Current.Resources["URLPREFIX"].ToString(), Application.Current.Resources["CATEGORYCONTROLLER"].ToString(), mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, category); if (!response.isSuccess) { IsRunning = false; IsEnable = true; await dialogService.ShowMessage(Languages.Error, response.Message); return; } ///Uso de singleton para acceder a la CategoriesViewModel category = (Category)response.Result; var categoriesViewModel = CategoriesViewModel.GetInstance(); //Metodo addcategory para refrescar la categoría categoriesViewModel.AddCategory(category); await navigationService.Back(); IsRunning = false; IsEnable = true; }
async void Save() { if (String.IsNullOrEmpty(Description)) { await dialogService.ShowMessage("Error", "You must enter a description"); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } var category = new Category { Description = Description, }; var mainViewModel = MainViewModel.GetInstance(); var response = await apiService.Post( "http://200.76.182.140:8085", "/api", "/Categories", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, category); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", response.Message); return; } category = (Category)response.Result; var categoriesViewModel = CategoriesViewModel.GetInstance(); categoriesViewModel.AddCategory(category); await navigationService.Back(); IsRunning = false; IsEnabled = true; }
private async void Save() { try { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You most enter an description."); return; } IsRunning = true; IsEnabled = false; var category = new Category(); category.Description = Description; var mainviewmodel = MainViewModel.GetInstance(); var response = await apiService.Post( "http://192.168.0.100", "/productsApi/api", "/Categories", mainviewmodel.Token.TokenType, mainviewmodel.Token.AccessToken, category); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } IsRunning = false; IsEnabled = true; category = (Category)response.Result; var categoriesViewModel = CategoriesViewModel.GetInstance(); categoriesViewModel.AddCategory(category); await navigationService.BackOnMaster(); } catch (Exception ex) { await dialogService.ShowMessage("Error", ex.Message); } }
async void SaveCategory() { if (string.IsNullOrEmpty(Description)) { await dialogServices.ShowMessage("Error", "Yeou must enter a category Description"); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogServices.ShowMessage("Error", connection.Message); return; } category.Description = Description; var mainViewModel = MainViewModel.GetInstance(); var response = await apiService.Put("http://productspalapi.azurewebsites.net", "/api", "/Categories", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, category); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogServices.ShowMessage("Errors", response.Message); return; } var categoriesViewModel = CategoriesViewModel.GetInstance(); categoriesViewModel.UpdateCategory(category); await navigationService.Back(); IsRunning = true; IsEnabled = false; }
async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter an Category."); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", connection.Message); return; } //Asignamos la nueva descripción al objeto, con lo que el usuario digitó category.Description = Description; var mainViewModels = MainViewModels.GetInstance(); var response = await apiService.Put( "http://productsapiis.azurewebsites.net", "/api", "/Categories", mainViewModels.Token.TokenType, mainViewModels.Token.AccessToken , category); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } var categoriesViewModel = CategoriesViewModel.GetInstance(); //actualizamos la categoria. categoriesViewModel.UpdateCategory(category); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }