private async void SelectCategoria() { App.codigoCategoriaEmpresa = this.Codigo; MainViewModel.GetInstance().Empresas.loadEmpresas(); MainViewModel.GetInstance().EmpresasProductos.loadEmpresasProductos(); await navigationService.BackOnMaster(); }
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; }
async void Sync() { IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", connection.Message); return; } var products = dataService.Get <Product>(false).Where(p => p.PendingToSave).ToList(); //validamos que haya productos if (products.Count == 0) { await dialogService.ShowMessage( "Error", "There are not products to sync!"); } var urlApi = Application.Current.Resources["URLAPI"].ToString(); var mainViewModels = MainViewModels.GetInstance(); foreach (var product in products) { var response = await apiService.Post( urlApi, "/api", "/Products", mainViewModels.Token.TokenType, mainViewModels.Token.AccessToken , product); if (response.IsSuccess) { product.PendingToSave = false; dataService.Update(product); } } IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Confirmation", "Data Base sync!!"); //Volvemos a la pagina principal await navigationService.BackOnMaster(); }
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 response = await apiService.Put( "http://products1apifjcc.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; } var categoriesViewModel = CategoriesViewModel.GetInstance(); categoriesViewModel.Update(category); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Sync() { IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); } var products = dataService.Get <Product>(false) .Where(p => p.PendingToSave) .ToList(); if (products.Count == 0) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Message", "There are not products to sync"); return; } var apiServiceWithoutConection = (ApiServiceWithoutConnection)apiService; var mainViewModel = MainViewModel.GetInstance(); foreach (var product in products) { var response = await apiServiceWithoutConection.PostProduct( "http://productszuluapi.azurewebsites.net", "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, product); if (response.IsSuccess) { product.PendingToSave = false; dataService.Delete(product); } } IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Confirm", "Sync operation Ok"); await navigationService.BackOnMaster(); }
async void Save() { if (string.IsNullOrEmpty(CurrentPassword)) { await dialogService.ShowMessage( "Error", "You must enter the current password."); return; } var mainViewModel = MainViewModel.GetInstance(); if (!mainViewModel.Token.Password.Equals(CurrentPassword)) { await dialogService.ShowMessage( "Error", "The current password is not valid"); return; } if (string.IsNullOrEmpty(NewPassword)) { await dialogService.ShowMessage( "Error", "You must enter a new password."); return; } if (NewPassword.Length < 6) { await dialogService.ShowMessage( "Error", "The new password must have at least 6 characters length."); return; } if (string.IsNullOrEmpty(ConfirmPassword)) { await dialogService.ShowMessage( "Error", "You must enter a new password confirm."); return; } if (!NewPassword.Equals(ConfirmPassword)) { await dialogService.ShowMessage( "Error", "The new password and confirm, does not match."); 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 changePasswordRequest = new ChangePasswordRequest { CurrentPassword = CurrentPassword, Email = mainViewModel.Token.UserName, NewPassword = NewPassword, }; //var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var urlAPI = "http://productszuluapi.azurewebsites.com"; var response = await((ApiServiceWithoutConnection)apiService).ChangePassword( urlAPI, "/api", "/Customers/ChangePassword", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, changePasswordRequest); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } mainViewModel.Token.Password = NewPassword; dataService.Update(mainViewModel.Token); await dialogService.ShowMessage( "Confirm", "The password was changed successfully"); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter an Product."); return; } if (string.IsNullOrEmpty(Price)) { await dialogService.ShowMessage( "Error", "You must enter an Price."); return; } var price = decimal.Parse(Price); if (price <= 0) { await dialogService.ShowMessage( "Error", "You must enter aun Price > 0"); } if (string.IsNullOrEmpty(Stock)) { await dialogService.ShowMessage( "Error", "You must enter an Stock."); return; } var stock = Double.Parse(Price); if (stock <= 0) { await dialogService.ShowMessage( "Error", "You must enter aun Stock > 0"); } if (string.IsNullOrEmpty(Stock)) { await dialogService.ShowMessage( "Error", "You must enter an Stock."); return; } byte[] imageArray = null; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); file.Dispose(); } var mainViewModels = MainViewModels.GetInstance(); var product = new Product { CategoryId = mainViewModels.Category.CategoryId, Description = Description, ImageArray = imageArray, IsActive = IsActive, LastPurchase = LastPurchase, Price = price, Remarks = Remarks, Stock = stock, }; IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { product.PendingToSave = true; dataService.Insert(product); await dialogService.ShowMessage( "Message", "The product was save to DB Local, don't forget to upload when to have connection to internet" ); } else { var response = await apiService.Post( "http://productsapiis.azurewebsites.net", "/api", "/Products", mainViewModels.Token.TokenType, mainViewModels.Token.AccessToken , product); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } product = (Product)response.Result; } var productsViewModel = ProductsViewModel.GetInstance(); productsViewModel.Add(product); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Save() { if (string.IsNullOrEmpty(CompanyName)) { await dialogService.ShowMessage("Erro", "Por favor insira o nome da empresa!"); return; } if (string.IsNullOrEmpty(CompanyNIF)) { await dialogService.ShowMessage("Erro", "Por favor insira o NIF da empresa!"); return; } IsRunning = true; IsEnabled = false; byte[] imageArray = null; try { if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); file.Dispose(); } } catch (Exception) { throw; } var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsEnabled = true; IsRunning = false; await dialogService.ShowMessage("Error", connection.Message); return; } var mainViewModel = MainViewModel.GetInstance(); var company = new Company { AddedDate = DateTime.Today, CompanyName = CompanyName, CompanyAddress = CompanyAddress, CompanyPhone = CompanyPhone, CompanyEmail = CompanyEmail, CompanyWebsite = CompanyWebsite, CompanySector = CompanySector, CompanyNIF = CompanyNIF, ImageArray = imageArray }; var response = await apiService.Post( "http://api.prospects.outstandservices.pt", "/api", "/Companies", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, company); if (!response.IsSuccess) { IsEnabled = true; IsRunning = false; await dialogService.ShowMessage("Error", response.Message); return; } //passa nova empresa para o viewmodel anterior company = (Company)response.Result; var companyViewModel = CompanyViewModel.GetInstance(); companyViewModel.AddCompany(company); await navigationService.BackOnMaster(); IsEnabled = true; IsRunning = false; }
async void SaveCommandMethod() { if (string.IsNullOrEmpty(ProductDescription)) { await dialogService.ShowMessage( "Error", "You must enter a product description... "); return; } _product.Description = ProductDescription; try { if (string.IsNullOrEmpty(Price)) { await dialogService.ShowMessage( "Error", "You must enter a product price... "); return; } _product.Price = decimal.Parse(Price); } catch (Exception ex) { await dialogService.ShowMessage( "Error", "You must enter a decimal product price... "); return; } try { _product.Stock = double.Parse(Stock); } catch (Exception ex) { await dialogService.ShowMessage( "Error", "You must enter a numeric product stock... "); return; } IsRunning = true; IsEnabled = false; _product.IsActive = IsActive; _product.Remarks = Remarks; _product.LastPurchase = LastPurchase; byte[] imageArray = null; var path = string.Empty; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); path = file.Path; _product.ImageArray = imageArray; _product.Image = path; file.Dispose(); } var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } var mainViewModel = MainViewModel.GetInstance(); var apiServiceWithoutConection = (ApiServiceWithoutConnection)apiService; var response = await apiServiceWithoutConection.PutProduct( "http://productszuluapi.azurewebsites.net", "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, _product); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } var productViewModel = mainViewModel.ProductsViewModel; productViewModel.UpdateProduct(_product); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void SaveCommandMethod() { if (string.IsNullOrEmpty(ProductDescription)) { await dialogService.ShowMessage( "Error", "You must enter a product description... "); return; } try { if (string.IsNullOrEmpty(Price)) { await dialogService.ShowMessage( "Error", "You must enter a product price... "); return; } var price = decimal.Parse(Price); } catch (Exception ex) { await dialogService.ShowMessage( "Error", "You must enter a decimal product price... "); return; } try { var stock = double.Parse(Stock); } catch (Exception ex) { await dialogService.ShowMessage( "Error", "You must enter a numeric product stock... "); return; } IsRunning = true; IsEnabled = false; byte[] imageArray = null; var path = string.Empty; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); path = file.Path; file.Dispose(); } var mainViewModel = MainViewModel.GetInstance(); var product = new Product() { CategoryId = mainViewModel.ProductsViewModel.Category.CategoryId, Description = ProductDescription, ImageArray = imageArray, IsActive = IsActive, LastPurchase = LastPurchase, Price = decimal.Parse(Price), Remarks = Remarks, Stock = double.Parse(Stock), Image = path }; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; product.PendingToSave = true; dataService.Insert(product); await dialogService.ShowMessage( "Message", "The product was save on local DB"); } else { var apiServiceWithoutConection = (ApiServiceWithoutConnection)apiService; var response = await apiServiceWithoutConection.PostProduct( "http://productszuluapi.azurewebsites.net", "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, product); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } product = (Product)response.Result; } var productViewModel = mainViewModel.ProductsViewModel; productViewModel.AddProduct(product); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
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; }
async void Save() { if (string.IsNullOrEmpty(FirstName)) { await dialogService.ShowMessage( "Error", "You must enter a first name."); return; } if (string.IsNullOrEmpty(LastName)) { await dialogService.ShowMessage( "Error", "You must enter a last name."); return; } if (string.IsNullOrEmpty(Email)) { await dialogService.ShowMessage( "Error", "You must enter a email."); return; } if (!RegexUtilities.IsValidEmail(Email)) { await dialogService.ShowMessage( "Error", "You must enter a valid email."); return; } if (string.IsNullOrEmpty(Password)) { await dialogService.ShowMessage( "Error", "You must enter a password."); return; } if (Password.Length < 6) { await dialogService.ShowMessage( "Error", "The password must have at least 6 characters length."); return; } if (string.IsNullOrEmpty(Confirm)) { await dialogService.ShowMessage( "Error", "You must enter a password confirm."); return; } if (!Password.Equals(Confirm)) { await dialogService.ShowMessage( "Error", "The password and confirm, does not match."); 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 customer = new Customer { Address = Address, CustomerType = 1, Email = Email, FirstName = FirstName, LastName = LastName, Password = Password, Phone = Phone, }; var response = await apiService.Post( "http://192.168.0.100", "/ProductsApi/api", "/Customers", customer); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } var response2 = await apiService.GetToken( "http://192.168.0.100/ProductsApi/", Email, Password); if (response2 == null) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", "The service is not available, please try latter."); Password = null; return; } if (string.IsNullOrEmpty(response2.AccessToken)) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response2.ErrorDescription); Password = null; return; } var mainViewModel = MainViewModel.GetInstance(); mainViewModel.Token = response2; mainViewModel.Categories = new CategoriesViewModel(); mainViewModel.Categories.Refresh(); await navigationService.BackOnMaster(); navigationService.SetMainPage("MasterView"); IsRunning = false; IsEnabled = true; }
async void Go() { if (string.IsNullOrEmpty(Descripcion)) { await dialogService.ShowMessage( "Error", "Debe ingresar una descripción."); 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 urlAPI = Application.Current.Resources["URLAPI"].ToString(); var tipoVehiculoViewModel = TipoVehiculoViewModel.GetInstance(); if (TitleBtn == "Agregar") { var tipoVehiculo = new TipoVehiculo { Descripcion = Descripcion, }; var response = await apiService.Post( urlAPI, "/api", "/TipoVehiculoes", tipoVehiculo); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } tipoVehiculo = (TipoVehiculo)response.Result; tipoVehiculoViewModel.Add(tipoVehiculo); await navigationService.BackOnMaster(); } if (TitleBtn == "Actualizar") { tipoVehiculo.Descripcion = Descripcion; var response = await apiService.Put( urlAPI, "/api", "/TipoVehiculoes", tipoVehiculo); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } tipoVehiculoViewModel.Update(tipoVehiculo); await navigationService.BackOnMaster(); } IsRunning = false; IsEnabled = true; }
async void Go() { if (string.IsNullOrEmpty(Descripcion)) { await dialogService.ShowMessage( "Error", "Debe ingresar una descripción."); return; } if (string.IsNullOrEmpty(Direccion)) { await dialogService.ShowMessage( "Error", "Debe ingresar una dirección."); return; } if (string.IsNullOrEmpty(NumeroZonas.ToString())) { await dialogService.ShowMessage( "Error", "Debe ingresar el número de zonas."); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } if (TitleBtn == "Agregar") { var parking = new Parking { Descripcion = Descripcion, Direccion = Direccion, NumeroZonas = NumeroZonas }; var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService.Post( urlAPI, "/api", "/Parqueos", parking); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } parking = (Parking)response.Result; var parqueoviewModel = ParqueoViewModel.GetInstance(); parqueoviewModel.Add(parking); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; } else { parking.Descripcion = Descripcion; parking.Direccion = Direccion; parking.NumeroZonas = NumeroZonas; var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService.Put( urlAPI, "/api", "/Parqueos", parking); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } var parqueosViewModel = ParqueoViewModel.GetInstance(); parqueosViewModel.Update(parking); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; } }
async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter a product description."); return; } if (string.IsNullOrEmpty(Price)) { await dialogService.ShowMessage( "Error", "You must enter a product price."); return; } var price = decimal.Parse(Price); if (price < 0) { await dialogService.ShowMessage( "Error", "The price must be a value greather or equals than zero."); return; } if (string.IsNullOrEmpty(Stock)) { await dialogService.ShowMessage( "Error", "You must enter a product stock."); return; } var stock = double.Parse(Stock); if (stock < 0) { await dialogService.ShowMessage( "Error", "The stock must be a value greather or equals than zero."); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } byte[] imageArray = null; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); file.Dispose(); } var mainViewModel = MainViewModel.GetInstance(); var product = new Product { CategoryId = mainViewModel.Category.CategoryId, Description = Description, ImageArray = imageArray, IsActive = IsActive, LastPurchase = LastPurchase, Price = price, Remarks = Remarks, Stock = stock, }; var response = await apiService.Post( "http://products1apifjcc.azurewebsites.net", "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, product); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } product = (Product)response.Result; var productsViewModel = ProductsViewModel.GetInstance(); productsViewModel.Add(product); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Go() { if (TitleBtn == "Agregar") { if (string.IsNullOrEmpty(Observation)) { await dialogService.ShowMessage( "Error", "Debe ingresar una observación."); 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 observacion = new Observacion { Descripcion = Observation, }; var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService.Post( urlAPI, "/api", "/Observacions", observacion); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } observacion = (Observacion)response.Result; var observacionViewModel = ObservacionViewModel.GetInstance(); observacionViewModel.Add(observacion); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; } else { if (string.IsNullOrEmpty(Observation)) { await dialogService.ShowMessage( "Error", "Debe ingresar una observación."); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage("Error", connection.Message); return; } observacion.Descripcion = Observation; var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService.Put( urlAPI, "/api", "/Observacions", observacion); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } var observacionViewModel = ObservacionViewModel.GetInstance(); observacionViewModel.Update(observacion); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; } }
async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter a product description."); return; } if (string.IsNullOrEmpty(Price)) { await dialogService.ShowMessage( "Error", "You must enter a product price."); return; } var price = decimal.Parse(Price); if (price < 0) { await dialogService.ShowMessage( "Error", "The price must be a value greather or equals than zero."); return; } if (string.IsNullOrEmpty(Stock)) { await dialogService.ShowMessage( "Error", "You must enter a product stock."); return; } var stock = double.Parse(Stock); if (stock < 0) { await dialogService.ShowMessage( "Error", "The stock must be a value greather or equals than zero."); return; } IsRunning = true; IsEnabled = false; byte[] imageArray = null; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); file.Dispose(); } var mainViewModel = MainViewModel.GetInstance(); var product = new Product { CategoryId = mainViewModel.Category.CategoryId, Description = Description, ImageArray = imageArray, IsActive = IsActive, LastPurchase = LastPurchase, Price = price, Remarks = Remarks, Stock = stock, }; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { product.PendingToSave = true; dataService.Insert(product); await dialogService.ShowMessage( "Message", "The product was save on local DB don't forget to " + "upload the record when you have WiFi."); } else { var urlAPI = Application.Current.Resources["URLAPI"].ToString(); var response = await apiService.Post( urlAPI, "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, product); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } product = (Product)response.Result; } var productsViewModel = ProductsViewModel.GetInstance(); productsViewModel.Add(product); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Save() { if (string.IsNullOrEmpty(Description)) { await dialogService.ShowMessage( "Error", "You must enter a product description."); return; } if (string.IsNullOrEmpty(Price)) { await dialogService.ShowMessage( "Error", "You must enter a product price."); return; } var price = decimal.Parse(Price); if (price < 0) { await dialogService.ShowMessage( "Error", "The price must be a value greather or equals than zero."); return; } if (string.IsNullOrEmpty(Stock)) { await dialogService.ShowMessage( "Error", "You must enter a product stock."); return; } var stock = double.Parse(Stock); if (stock < 0) { await dialogService.ShowMessage( "Error", "The stock must be a value greather or equals than zero."); 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 mainViewModel = MainViewModel.GetInstance(); var urlAPI = Application.Current.Resources["URLAPI"].ToString(); byte[] imageArray = null; if (file != null) { imageArray = FilesHelper.ReadFully(file.GetStream()); file.Dispose(); } product.Description = Description; product.IsActive = IsActive; product.LastPurchase = LastPurchase; product.Price = price; product.Remarks = Remarks; product.Stock = stock; product.ImageArray = imageArray; var response = await apiService.Put( urlAPI, "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, product); if (!response.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", response.Message); return; } ProductsViewModel.GetInstance().Update(product); await navigationService.BackOnMaster(); IsRunning = false; IsEnabled = true; }
async void Save() { if (string.IsNullOrEmpty(ContactName)) { await dialogService.ShowMessage("Erro", "Por favor insira o nome do contacto!"); return; } if (string.IsNullOrEmpty(ContactEmail)) { await dialogService.ShowMessage("Erro", "Por favor insira o Email do contacto!"); return; } IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsEnabled = true; IsRunning = false; await dialogService.ShowMessage("Error", connection.Message); return; } var mainViewModel = MainViewModel.GetInstance(); contact.ContactName = ContactName; contact.ContactMobile = ContactMobile; contact.ContactEmail = ContactEmail; contact.CompanyId = mainViewModel.Company.CompanyId; contact.ContactPositionInCompany = ContactPositionInCompany; var response = await apiService.Put( "http://api.prospects.outstandservices.pt", "/api", "/Contacts", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, contact); if (!response.IsSuccess) { IsEnabled = true; IsRunning = false; await dialogService.ShowMessage("Error", response.Message); return; } var contactViewModel = ContactsViewModel.GetInstance(); contactViewModel.UpdateContact(contact); await navigationService.BackOnMaster(); IsEnabled = true; IsRunning = false; }
async void Sync() { IsRunning = true; IsEnabled = false; var connection = await apiService.CheckConnection(); if (!connection.IsSuccess) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", connection.Message); return; } var products = dataService.Get <Product>(false) .Where(p => p.PendingToSave) .ToList(); if (products.Count == 0) { IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Error", "There are not products to sync."); return; } var mainViewModel = MainViewModel.GetInstance(); var urlAPI = Application.Current.Resources["URLAPI"].ToString(); double progress = (double)1 / products.Count; Progress = 0; foreach (var product in products) { var response = await apiService.Post( urlAPI, "/api", "/Products", mainViewModel.Token.TokenType, mainViewModel.Token.AccessToken, product); if (response.IsSuccess) { product.PendingToSave = false; dataService.Update(product); } Progress += progress; } IsRunning = false; IsEnabled = true; await dialogService.ShowMessage( "Confirmation", "Sync Ok"); Progress = 0; await navigationService.BackOnMaster(); }