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 conecction = await this.apiService.CheckConnection(); if (!conecction.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, conecction.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.Token_type, Settings.Access_token); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Accept); return; } var productsViewModel = ProductsViewModel.GetIntance(); 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 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; var conecction = await this.apiService.CheckConnection(); if (!conecction.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, conecction.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.Token_type, Settings.Access_token); 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.GetIntance(); 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.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; } if (this.Category == null) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.CategoryError, Languages.Accept); return; } this.IsRunning = true; this.IsEnabled = false; var conecction = await this.apiService.CheckConnection(); if (!conecction.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, conecction.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.GetIntance().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.Token_type, Settings.Access_token); 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.GetIntance(); productsViewModel.MyProducts.Add(newProduct); productsViewModel.RefreshList(); this.IsRunning = false; this.IsEnabled = true; await App.Navigator.PopAsync(); }